Skip to content

Commit

Permalink
feat: add provide function
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Sep 22, 2023
1 parent 7a21933 commit ecc9650
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
16 changes: 7 additions & 9 deletions docs/i18n.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ registerLocaleData(zh);
`ng-zorro-antd` internationalization defaults to the Chinese version, for example the default English version:

```ts
import { NZ_I18N, en_US } from 'ng-zorro-antd/i18n';
import { en_US, provideNzI18n } from 'ng-zorro-antd/i18n';
@NgModule({
...
imports : [ NgZorroAntdModule ],
providers : [ { provide: NZ_I18N, useValue: en_US } ]
providers: [provideNzI18n(en_US)]
})
export class AppModule { }
export class App1Module {}
```

Of course, you can also use runtime changes:
Expand Down Expand Up @@ -144,7 +142,7 @@ In order to make language uniformity, NG-ALAIN provides a simple unified configu
```ts
// #region i18n
import { default as ngLang } from '@angular/common/locales/zh';
import { NZ_I18N, zh_CN as zorroLang } from 'ng-zorro-antd/i18n';
import { provideNzI18n, zh_CN as zorroLang } from 'ng-zorro-antd/i18n';
import { DELON_LOCALE, zh_CN as delonLang } from '@delon/theme';
const LANG = {
abbr: 'zh',
Expand All @@ -157,7 +155,7 @@ import { registerLocaleData } from '@angular/common';
registerLocaleData(LANG.ng, LANG.abbr);
const LANG_PROVIDES = [
{ provide: LOCALE_ID, useValue: LANG.abbr },
{ provide: NZ_I18N, useValue: LANG.zorro },
provideNzI18n(LANG.zorro),
{ provide: DELON_LOCALE, useValue: LANG.delon },
];
// #endregion
Expand All @@ -173,7 +171,7 @@ export class AppModule {}
```ts
// #region i18n
import { default as ngLang } from '@angular/common/locales/en';
import { NZ_I18N, en_US as zorroLang } from 'ng-zorro-antd/i18n';
import { provideNzI18n, en_US as zorroLang } from 'ng-zorro-antd/i18n';
import { DELON_LOCALE, en_US as delonLang } from '@delon/theme';
const LANG = {
abbr: 'en',
Expand All @@ -186,7 +184,7 @@ import { registerLocaleData } from '@angular/common';
registerLocaleData(LANG.ng, LANG.abbr);
const LANG_PROVIDES = [
{ provide: LOCALE_ID, useValue: LANG.abbr },
{ provide: NZ_I18N, useValue: LANG.zorro },
provideNzI18n(LANG.zorro),
{ provide: DELON_LOCALE, useValue: LANG.delon },
];
// #endregion
Expand Down
16 changes: 7 additions & 9 deletions docs/i18n.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ registerLocaleData(zh);
NG-ZORRO 国际化默认是中文版,例如默认为英文版本:

```ts
import { NZ_I18N, en_US } from 'ng-zorro-antd/i18n';
import { en_US, provideNzI18n } from 'ng-zorro-antd/i18n';
@NgModule({
...
imports : [ NgZorroAntdModule ],
providers : [ { provide: NZ_I18N, useValue: en_US } ]
providers: [provideNzI18n(en_US)]
})
export class AppModule { }
export class App1Module {}
```

当然,也可以使用运行时更改:
Expand Down Expand Up @@ -144,7 +142,7 @@ export class I18nTestComponent {
```ts
// #region i18n
import { default as ngLang } from '@angular/common/locales/zh';
import { NZ_I18N, zh_CN as zorroLang } from 'ng-zorro-antd/i18n';
import { provideNzI18n, zh_CN as zorroLang } from 'ng-zorro-antd/i18n';
import { DELON_LOCALE, zh_CN as delonLang } from '@delon/theme';
const LANG = {
abbr: 'zh',
Expand All @@ -157,7 +155,7 @@ import { registerLocaleData } from '@angular/common';
registerLocaleData(LANG.ng, LANG.abbr);
const LANG_PROVIDES = [
{ provide: LOCALE_ID, useValue: LANG.abbr },
{ provide: NZ_I18N, useValue: LANG.zorro },
provideNzI18n(LANG.zorro),
{ provide: DELON_LOCALE, useValue: LANG.delon },
];
// #endregion
Expand All @@ -173,7 +171,7 @@ export class AppModule {}
```ts
// #region i18n
import { default as ngLang } from '@angular/common/locales/en';
import { NZ_I18N, en_US as zorroLang } from 'ng-zorro-antd/i18n';
import { provideNzI18n, en_US as zorroLang } from 'ng-zorro-antd/i18n';
import { DELON_LOCALE, en_US as delonLang } from '@delon/theme';
const LANG = {
abbr: 'en',
Expand All @@ -186,7 +184,7 @@ import { registerLocaleData } from '@angular/common';
registerLocaleData(LANG.ng, LANG.abbr);
const LANG_PROVIDES = [
{ provide: LOCALE_ID, useValue: LANG.abbr },
{ provide: NZ_I18N, useValue: LANG.zorro },
provideNzI18n(LANG.zorro),
{ provide: DELON_LOCALE, useValue: LANG.delon },
];
// #endregion
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"extend": "^3.0.2",
"file-saver": "^2.0.5",
"ng-github-button": "^16.0.0",
"ng-zorro-antd": "^16.1.0",
"ng-zorro-antd": "^16.2.0",
"ngx-color": "~9.0.0",
"ngx-countdown": "^16.0.0",
"ngx-highlight-js": "^16.1.0",
Expand Down
4 changes: 2 additions & 2 deletions schematics/application/files/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Observable } from 'rxjs';
import { default as ngLang } from '@angular/common/locales/zh';
import { DELON_LOCALE, zh_CN as delonLang } from '@delon/theme';
import { zhCN as dateLang } from 'date-fns/locale';
import { NZ_DATE_LOCALE, NZ_I18N, zh_CN as zorroLang } from 'ng-zorro-antd/i18n';
import { NZ_DATE_LOCALE, provideNzI18n, zh_CN as zorroLang } from 'ng-zorro-antd/i18n';
const LANG = {
abbr: 'zh',
ng: ngLang,
Expand All @@ -26,7 +26,7 @@ import { registerLocaleData } from '@angular/common';
registerLocaleData(LANG.ng, LANG.abbr);
const LANG_PROVIDES = [
{ provide: LOCALE_ID, useValue: LANG.abbr },
{ provide: NZ_I18N, useValue: LANG.zorro },
provideNzI18n(LANG.zorro),
{ provide: NZ_DATE_LOCALE, useValue: LANG.date },
{ provide: DELON_LOCALE, useValue: LANG.delon },
];
Expand Down
2 changes: 2 additions & 0 deletions schematics/plugin/plugin.default-language.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('NgAlainSchematic: plugin: default-language', () => {
const content = tree.readContent(PATH);
expect(content).toContain(`@angular/common/locales/en`);
expect(content).toContain(`NZ_I18N, en_US`);
expect(content).toContain(`provideNzI18n, en_US`);
expect(content).toContain(`DELON_LOCALE, en_US`);
});

Expand All @@ -22,6 +23,7 @@ describe('NgAlainSchematic: plugin: default-language', () => {
const content = tree.readContent(PATH);
expect(content).toContain(`@angular/common/locales/zh`);
expect(content).toContain(`NZ_I18N, zh_CN`);
expect(content).toContain(`provideNzI18n, zh_CN`);
expect(content).toContain(`DELON_LOCALE, zh_CN`);
});
});
1 change: 1 addition & 0 deletions schematics/plugin/plugin.default-language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function pluginDefaultLanguage(options: PluginOptions): Rule {
.replace(/abbr: '([^']+)/, `abbr: '${options.defaultLanguage}`);
// zorro
content = content.replace(/NZ_I18N, ([^ ]+)/, `NZ_I18N, ${targetLang.zorro}`);
content = content.replace(/provideNzI18n, ([^ ]+)/, `provideNzI18n, ${targetLang.zorro}`);
// delon
content = content.replace(/DELON_LOCALE, ([^ ]+)/, `DELON_LOCALE, ${targetLang.zorro}`);
tree.overwrite(modulePath, content);
Expand Down
5 changes: 3 additions & 2 deletions src/app/core/code/files/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RouterModule } from '@angular/router';
import { DemoNgZorroAntdModule } from './ng-zorro-antd.module';
import { NZ_ICONS } from 'ng-zorro-antd/icon';
import { NZ_I18N, en_US } from 'ng-zorro-antd/i18n';
import { provideNzI18n, en_US } from 'ng-zorro-antd/i18n';
import { IconDefinition } from '@ant-design/icons-angular';
import * as AllIcons from '@ant-design/icons-angular/icons';
Expand Down Expand Up @@ -62,7 +62,8 @@ providers: [
deps: [StartupService],
multi: true
},
{ provide: NZ_I18N, useValue: en_US }, { provide: NZ_ICONS, useValue: icons }
provideNzI18n(en_US),
{ provide: NZ_ICONS, useValue: icons }
],
declarations: [ ${componentName} ],
bootstrap: [ ${componentName} ]
Expand Down

0 comments on commit ecc9650

Please sign in to comment.