Last active
December 11, 2019 16:11
-
-
Save wesleygrimes/9f0ab74e853854c988eb793edaeef845 to your computer and use it in GitHub Desktop.
Transloco Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpClientModule } from '@angular/common/http'; | |
import { Injector, NgModule, NgZone } from '@angular/core'; | |
import { BrowserModule } from '@angular/platform-browser'; | |
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | |
import { SharedLocalizationModule } from '../shared/localization'; | |
import { environment } from '../environments/environment'; | |
import { AppComponent } from './app.component'; | |
@NgModule({ | |
imports: [ | |
BrowserModule, | |
BrowserAnimationsModule, | |
HttpClientModule, | |
SharedLocalizationModule.forRoot(environment.production), | |
], | |
providers: [], | |
declarations: [AppComponent, EmptyComponent], | |
bootstrap: [AppComponent] | |
}) | |
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CommonModule } from '@angular/common'; | |
import { HttpClientModule } from '@angular/common/http'; | |
import { NgModule, Injector } from '@angular/core'; | |
import { MyLocalizationModule } from '../localization'; | |
@NgModule({ | |
imports: [ | |
CommonModule, | |
HttpClientModule, | |
MyLocalizationModule, | |
], | |
declarations: [ | |
MyComponent, | |
], | |
providers: [], | |
exports: [], | |
}) | |
export class MyFeatureeModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import { CommonModule } from '@angular/common'; | |
import { TranslocoModule, TRANSLOCO_SCOPE } from '@ngneat/transloco'; | |
import { TranslocoLocaleModule } from '@ngneat/transloco-locale'; | |
import { SomeService } from '../services/some.service'; | |
import { myScope } from './my-scope'; | |
@NgModule({ | |
imports: [CommonModule, TranslocoModule, TranslocoLocaleModule], | |
providers: [ | |
{ | |
provide: TRANSLOCO_SCOPE, | |
deps: [SomeService], | |
useFactory: myScope | |
} | |
], | |
exports: [TranslocoModule, TranslocoLocaleModule] | |
}) | |
export class MyLocalizationModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SomeService } from '../services/some.service'; | |
import { of } from 'rxjs'; | |
export const getTranslations = (someService: SomeService, lang:" string) => () => { | |
if (lang === 'en-us') { | |
const i18n = someService.getEnglish(); //returns synchronous object | |
const translations = { | |
...i18n.obj1, | |
...i18n.obj2 | |
}; | |
return of(translations).toPromise(); | |
} | |
if (lang === 'es-us') { | |
const i18n = someService.getSpanish(); //returns synchronous object | |
const translations = { | |
...i18n.obj1, | |
...i18n.obj2 | |
}; | |
return of(translations).toPromise(); | |
} | |
}; | |
export const scopeLoader = (someService: SomeService, loader = getTranslations) => { | |
return { | |
'en-us': loader(someService, 'en-us'), | |
'es-us': loader(someService, 'es-us') | |
}; | |
}; | |
export const myScope = (someService: SomeService) => ({ | |
scope: 'myScope', | |
loader: scopeLoader(someService) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment