ngx-translate
Some manual changes may still be required after the script has executed.
Command
ng g @jsverse/transloco:migrate
# On an nx workspace
nx g @jsverse/transloco:migrate
What will be done?
The script will iterate recursively over all your HTML
and TS
files and will execute the replacements described below:
Pipes
The translate
pipes will be replaced with the transloco
pipe.
Examples:
{{ "hello.world" | translate }}
will be replaced with{{ "hello.world" | transloco }}
{{ "hello.world" | translate | anotherPipe | oneMore ... }}
will be replaced with{{ "hello.world" | transloco | anotherPipe | oneMore ... }}
{{ "hello" | translate:{name: 'Jhon'} }}
will be replaced with{{ "hello" | transloco:{name: 'Jhon'} }}
{{ "hello" | translate:{name: 'Jhon'} | anotherPipe }}
will be replaced with{{ "hello" | transloco:{name: 'Jhon'} | anotherPipe }}
<component [header]="'hello.world' | translate"...
will be replaced with<component [header]="'hello.world' | transloco"...
<component [header]="'hello.world' | translate | anotherPipe"...
will be replaced with<component [header]="'hello.world' | transloco | anotherPipe"...
<component [header]="'hello' | translate:params | anotherPipe"...
will be replaced with<component [header]="'hello' | transloco:params | anotherPipe"...
Directives
The translate
& translateParams
directives will be replaced with the matching transloco
directives.
Examples:
<div [translate]="'HELLO'" [translateParams]="{value: 'world'}"></div>
will be replaced with<div [transloco]="'HELLO'" [translocoParams]="{value: 'world'}"></div>
Imports
The TranslateService
imports will be replaced with TranslocoService
.
Examples:
import {TranslateService} from '@ngx-translate/core';
will be replaced withimport { TranslocoService } from '@jsverse/transloco';
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
will be replaced withimport {TranslateLoader} from '@ngx-translate/core';
import { TranslocoService } from '@jsverse/transloco';
Constructor Injections
The TranslateService
injections will be replaced with TranslocoService
.
Examples:
constructor(private translate: TranslateService) {
will be replaced withconstructor(private translate: TranslocoService) {
Service Usages
translateService.currentLang
will be replaced withtranslateService.getActiveLang()
.translateService.onLangChange
will be replaced withtranslateService.langChanges$
.translateService.use(...)
calls will be replaced withtranslateService.setActiveLang(...)
.translateService.instant(...)
calls will be replaced withtranslateService.translate(...)
.translateService.get(...)
calls will be replaced withtranslateService.selectTranslate(...)
andtake(1)
needs to be manually addedtranslateService.selectTranslate(...).pipe(take(1))
in order to prevent listening to language changes.translateService.stream(...)
calls will be replaced withtranslateService.selectTranslate(...)
.translateService.set(...)
calls will be replaced withtranslateService.setTranslation(...)
.
Examples:
const translation = this.translateService.instant('hello')
will be replaced withconst translation = this.translateService.translate('hello')
Manual Replacements
getBrowserLang()
- In Transloco it's a pure function that needs to be imported.getBrowserCultureLang()
- In Transloco it's a pure function that needs to be imported.currentLoader
- No equivalent in Transloco.addLangs(...)
- No equivalent in Transloco.getLangs(...)
- No equivalent in Transloco.reloadLang(...)
- No equivalent in Transloco.resetLang(...)
- No equivalent in Transloco.
Modules
TranslateModule
& TranslateModule.forChild(...)
& TranslateModule.forRoot(...)
will be replaced with TranslocoModule
Examples:
TranslateModule.forChild({ loader: { provide: TranslateLoader, useFactory: HttpLoaderFactory, deps: [HttpClient] } })
will be replaced withTranslocoModule
Specs
Imports, Modules and TranslateService
will be replaced with TranslocoService
Issues
If you encounter any issues with the migration script please open a github issue so we can resolve them and make a better experience for all.