Giter Site home page Giter Site logo

Comments (4)

nnixaa avatar nnixaa commented on May 18, 2024

@sanathpathiraja if you want to globally include translate pipe, add it to APPLICATION_PIPES array in src\platform\browser\pipes.ts. In this case, you won't need to import and explicitly register the pipe in each component.

from ngx-admin.

sanathpathiraja avatar sanathpathiraja commented on May 18, 2024

yes i did that.

app/index.ts
// App
import {AppState} from "./app.state";
import {TRANSLATE_PROVIDERS,
TranslateService,
TranslateLoader,
TranslateStaticLoader} from 'ng2-translate/ng2-translate';
import {provide} from '@angular/core';
import {Http} from '@angular/http';
export * from './app.component';

// Application wide providers
export const APP_PROVIDERS = [
AppState,
provide(TranslateLoader, {
useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
deps: [Http]
}),
TRANSLATE_PROVIDERS,
TranslateService
];

app.component.ts
import {TRANSLATE_PROVIDERS, TranslateService, TranslatePipe, TranslateLoader, TranslateStaticLoader} from 'ng2-translate/ng2-translate';
export class App {

isMenuCollapsed:boolean = false;
constructor(private _state:AppState, private _imageLoader:BaImageLoaderService, private _spinner:BaThemeSpinner, translate: TranslateService) {
translate.setDefaultLang('en');

but translate not working.
can you help me?

from ngx-admin.

nnixaa avatar nnixaa commented on May 18, 2024

@sanathpathiraja still you haven't loaded the pipe globally, here the minimal steps:

  1. install the module
  2. in src/platform/broswers/pipes.ts add translate pipe like this:
import {TranslatePipe} from 'ng2-translate/ng2-translate';

// application_pipes: pipes that are global through out the application
export const APPLICATION_PIPES = [
  TranslatePipe // <----- add the pipe HERE
];

// the rest of the code
  1. in src/platform/broswers/providers.ts add TRANSLATE_PROVIDERS like this:
import {TRANSLATE_PROVIDERS} from 'ng2-translate/ng2-translate';

/*
* Application Providers/Directives/Pipes
* providers/directives/pipes that only live in our browser environment
*/
export const APPLICATION_PROVIDERS = [
  ...FORM_PROVIDERS,
  ...HTTP_PROVIDERS,
  ...ROUTER_PROVIDERS,
  TRANSLATE_PROVIDERS, // <--- HERE the providers
  {provide: LocationStrategy, useClass: HashLocationStrategy }
];

// the rest of the code
  1. now use it in any template you need to

from ngx-admin.

sanathpathiraja avatar sanathpathiraja commented on May 18, 2024

yes, I added that after I change
src/main.browser.js

`export function main(initialHmrState?: any): Promise {

return bootstrap(App, [
...PROVIDERS,
...ENV_PROVIDERS,
...DIRECTIVES,
...PIPES,
...APP_PROVIDERS,
HTTP_PROVIDERS,
provide(TranslateLoader, {
useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
deps: [Http]
}),
// use TranslateService here, and not TRANSLATE_PROVIDERS (which will define a default TranslateStaticLoader)
TranslateService
])
.catch(err => console.error(err));`

after run it perfectly.
thanks @nnixaa

from ngx-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.