Code Monkey home page Code Monkey logo

Comments (6)

robisim74 avatar robisim74 commented on May 26, 2024 1

Sorry, but I don't understand what you are trying to do. However: for the first option, in the AppModule you have to use:

  imports: [ 
    LocaleModule.forRoot(), // New instance of LocaleService.
    LocalizationModule.forRoot(), // New instance of LocalizationService.
    ....
  ],

so you create the new instances of the services.

In all the other sub-modules, you have to use:

    imports: [
        ...
        LocaleModule, // LocaleService is singleton.
        LocalizationModule // LocalizationService is singleton.
    ]

and remove from the providers:

    LocaleService,
    LocalizationService

otherwise you create other instances.

from angular-l10n.

robisim74 avatar robisim74 commented on May 26, 2024 1

You'll never know until you try... :)

from angular-l10n.

robisim74 avatar robisim74 commented on May 26, 2024 1

@Shiroh1ge I'm closing this issue. If you need, open a new issue. Greetings

from angular-l10n.

robisim74 avatar robisim74 commented on May 26, 2024

If you are using lazy loaded modules with the router, there are two scenarios:

  1. You want to use the same translation files for the whole application.

You must not call the forChild method, because it creates a new instance of the service. So you have to use:

    imports: [
        ...
        LocaleModule, // LocaleService is singleton.
        LocalizationModule // LocalizationService is singleton.
    ]
  1. You want to use different translation files for each module.

You must call the forChild method:

    imports: [
        ...
        LocaleModule, // LocaleService is singleton.
        LocalizationModule.forChild() // New instance of LocalizationService.
    ]

But you have to reinitialize LocalizationService with new providers, as explained here: https://github.com/robisim74/angular2localization/blob/master/doc/spec.md#5
Also the List module/component of the sample app is built in this way: https://github.com/robisim74/angular2localization/tree/gh-pages

from angular-l10n.

Shiroh1ge avatar Shiroh1ge commented on May 26, 2024

Thanks for the quick response. I have been trying to do the first option you mentionted and I don't seem to get it to work. I have moved the modules to my CoreModule and have created a HomeModule for my HomeComponent. This should allow it to use any services from the CoreModule, right? This is my CoreModule:

imports...

@NgModule({
  imports: [  
    SharedModule,
    RouterModule,
    LocaleModule, //  LocaleService is singleton.
    LocalizationModule, // LocalizationService is singleton.
  ],
  declarations: [],  
  exports: [],   
  providers: [
    UserService,
    LocaleService,
    LocalizationService
  ]
})

export class CoreModule {}

My AppComponent is the same. So, shouldn't LocaleService and LocalizationService be available everywhere? Right now, my Home page is not getting translated, unless I import the LocaleModule and LocalizationModule inside the HomeModule. Is this how it works and must I import these modules in every feature module or am I doing something wrong elsewhere?

from angular-l10n.

Shiroh1ge avatar Shiroh1ge commented on May 26, 2024

Sorry, but I don't understand what you are trying to do.

Neither do I, lol! Anyway, I've been doing it wrong, thanks for your help, everything is clear to me now and it works. I just couldn't comprehend how it all works I guess. Thanks a lot for the help!

from angular-l10n.

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.