Скрипт для angular 6+, для интернациализации.
Три варинта использование:
- GraphQl адрес
- Http/s адрес
- Передача файла json
npm i --save mz-dictionary
@NgModule({
declarations: [
AppComponent,
SignComponent,
LkComponent,
AppMenuBlockComponent,
AppMenuLeftFooterControllerComponent
],
imports: [
BrowserModule,
MzDictionaryModule.forRoot(
{
type: MzDictionaryInputTypeEnum.json,
data: {
defaultLanguage: MzLanguageEnum.ru,
dictionary: [
{
key: "test",
value: {
en: "ABCD",
ru: "АБВГ"
}
},
{
key: "test.abc",
value: {
en: "ABCDABCD",
ru: "АБВГАБВГ"
}
}
],
hash: "3",
includedLanguages: [MzLanguageEnum.en, MzLanguageEnum.ru],
possibleLanguages: [MzLanguageEnum.en, MzLanguageEnum.ru],
status: true
},
// syncInterval: 30000 , // @default - 10 minutes
}
),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
@NgModule({
declarations: [
AppComponent,
SignComponent,
LkComponent,
AppMenuBlockComponent,
AppMenuLeftFooterControllerComponent
],
imports: [
BrowserModule,
MzDictionaryModule.forRoot(
{
type: MzDictionaryInputTypeEnum.graphQl,
url: 'https://some-site.net/path/to/endpoint'
}
),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
@NgModule({
declarations: [
AppComponent,
SignComponent,
LkComponent,
AppMenuBlockComponent,
AppMenuLeftFooterControllerComponent
],
imports: [
BrowserModule,
MzDictionaryModule.forRoot(
{
type: MzDictionaryInputTypeEnum.http,
url: 'https://some-site.net/path/to/endpoint'
}
),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
}
<a href="#" mz-dictionary>Забыли пароль<b href="#">test-abc - [[test.abc]]</b> || <i>test - [[test]]</i></a>
<a href="#" mz-dictionary="@outerHTML">Забыли пароль<b href="#">test-abc - [[test.abc]]</b> || <i>test - [[test]]</i></a>
<input href="#" mz-dictionary="placeholder" placeholder="Тут [[some.dictionary.key]]">
<input href="#" [mz-dictionary]="['placeholder, someAttr']" someAttr="Еще тут [[some.else]]" placeholder="Тут [[some.dictionary.key]]">
<input href="#" mz-dictionary="placeholder, someAttr" someAttr="Еще тут [[some.else]]" placeholder="Тут [[some.dictionary.key]]">