-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fic(core): translatemodule forRoot is now called once (#1551)
* feat: update Angular v17 * fix(geo): do not upgrade flexsearch since it seem not compatible with TS nextapps-de/flexsearch#342 * fix(core/language): TranslateModule call forRoot only once with provideRootTranslation - IgoLanguageModule only export the TranslateModule BREAKING CHANGE: IgoLanguageModule don't import TranslateModule.forRoot defaultLanguageLoader is not exported anymore - provideDefaultLanguageLoader and provideLanguageLoader are replaced by DEFAULT_LANGUAGE_LOADER and set directly inside the TranslationConfig * fix(auth): test
- Loading branch information
Showing
11 changed files
with
77 additions
and
62 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,8 @@ | ||
import { ModuleWithProviders, NgModule } from '@angular/core'; | ||
import { NgModule } from '@angular/core'; | ||
|
||
import { | ||
MissingTranslationHandler, | ||
TranslateModule | ||
} from '@ngx-translate/core'; | ||
|
||
import { provideDefaultLanguageLoader } from './shared/language.provider'; | ||
import { IgoMissingTranslationHandler } from './shared/missing-translation.guard'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
TranslateModule.forRoot({ | ||
missingTranslationHandler: { | ||
provide: MissingTranslationHandler, | ||
useClass: IgoMissingTranslationHandler | ||
} | ||
}) | ||
], | ||
declarations: [], | ||
exports: [TranslateModule] | ||
}) | ||
export class IgoLanguageModule { | ||
static forRoot(): ModuleWithProviders<IgoLanguageModule> { | ||
return { | ||
ngModule: IgoLanguageModule, | ||
providers: [provideDefaultLanguageLoader()] | ||
}; | ||
} | ||
} | ||
export class IgoLanguageModule {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './language.interface'; | ||
export * from './language.loader'; | ||
export * from './language.provider'; | ||
export * from './language.service'; | ||
export * from './missing-translation.guard'; |
58 changes: 39 additions & 19 deletions
58
packages/core/src/lib/language/shared/language.provider.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,49 @@ | ||
import { HttpBackend } from '@angular/common/http'; | ||
import { ImportProvidersSource, Provider } from '@angular/core'; | ||
|
||
import { TranslateLoader } from '@ngx-translate/core'; | ||
import { | ||
MissingTranslationHandler, | ||
TranslateLoader, | ||
TranslateModule, | ||
TranslateModuleConfig | ||
} from '@ngx-translate/core'; | ||
|
||
import { ConfigService } from '../../config/config.service'; | ||
import { ConfigService } from '../../config'; | ||
import { LanguageLoader } from './language.loader'; | ||
import { IgoMissingTranslationHandler } from './missing-translation.guard'; | ||
|
||
export function defaultLanguageLoader( | ||
http: HttpBackend, | ||
config?: ConfigService | ||
) { | ||
return new LanguageLoader(http, undefined, undefined, config); | ||
/** | ||
* Make sure you only call this method in the root module of your application, most of the time called AppModule. | ||
*/ | ||
export function provideRootTranslation( | ||
loader?: Provider | ||
): ImportProvidersSource { | ||
return TranslateModule.forRoot(setTranslationConfig(loader)); | ||
} | ||
|
||
export function provideLanguageLoader(loader?) { | ||
return { | ||
provide: TranslateLoader, | ||
useFactory: loader || defaultLanguageLoader, | ||
deps: [HttpBackend] | ||
}; | ||
export function provideMockTranslation( | ||
loader?: Provider | ||
): ImportProvidersSource { | ||
return TranslateModule.forRoot(); | ||
} | ||
|
||
export function provideDefaultLanguageLoader(loader?) { | ||
return { | ||
provide: TranslateLoader, | ||
useFactory: loader || defaultLanguageLoader, | ||
deps: [HttpBackend, ConfigService] | ||
}; | ||
export const setTranslationConfig = ( | ||
loader?: Provider | ||
): TranslateModuleConfig => ({ | ||
defaultLanguage: 'en', | ||
loader: loader ?? DEFAULT_LANGUAGE_LOADER, | ||
missingTranslationHandler: { | ||
provide: MissingTranslationHandler, | ||
useClass: IgoMissingTranslationHandler | ||
} | ||
}); | ||
|
||
export const DEFAULT_LANGUAGE_LOADER: Provider = { | ||
provide: TranslateLoader, | ||
useFactory: defaultLanguageLoader, | ||
deps: [HttpBackend, ConfigService] | ||
}; | ||
|
||
function defaultLanguageLoader(http: HttpBackend, config?: ConfigService) { | ||
return new LanguageLoader(http, undefined, undefined, config); | ||
} |
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
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
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
6 changes: 5 additions & 1 deletion
6
projects/demo/src/app/core/monitoring/monitoring.component.spec.ts
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
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