Comments (6)
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.
You'll never know until you try... :)
from angular-l10n.
@Shiroh1ge I'm closing this issue. If you need, open a new issue. Greetings
from angular-l10n.
If you are using lazy loaded modules with the router, there are two scenarios:
- 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.
]
- 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.
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.
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)
- How i can translate the word HOT 1
- feature: easily register and bundle translation data with a lazy loaded module HOT 3
- Number format options HOT 7
- Release a version with peerDependencies compatible with RxJS v7 HOT 3
- split big files HOT 2
- Namespace 'Intl' has no exported member 'RelativeTimeFormatOptions' HOT 3
- [Question] Differences / Benefits vs ngx-translate? HOT 3
- Setting available languages from Database HOT 5
- Problems after Upgrading HOT 2
- locale.language is empty, Error: angular-l10n (L10nDefaultTranslationLoader): Asset not found HOT 2
- Incorrect date format HOT 2
- Namespace 'Intl' has no exported member 'ListFormatOptions' HOT 1
- possibility to configure PARSE_DATE_STYLE const. Configure full, long,medium,short options HOT 2
- Refreshing page redirects to fallback HOT 5
- Opening subpages in tabs works - sometimes HOT 1
- I encountered this problem: Unexpected value 'TranslateModule' imported by the module 'SharedModule'. Please add an @NgModule annotation. HOT 2
- angular-l10n used in angular component being imported from react parent application as library doesnot work HOT 8
- Is it possible to use angular-l10n to support custom translations in library1 while the config for translations stays in the main app that uses library1? HOT 10
- Json file convertion to js chunk creates a sublevel: [lang]_default HOT 2
- Allow for template elements inside of params HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-l10n.