Skip to content

Commit

Permalink
feat: query国际化
Browse files Browse the repository at this point in the history
  • Loading branch information
EnochGao committed Aug 18, 2023
1 parent c7816d4 commit 0e7181b
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@
<div class="nzx-query-btn" nz-col [nzSpan]="nzxBtnSpan || 24 / lineNumber">
<div nz-row nzJustify="end" nzAlign="middle">
<button nz-button nzType="primary" type="button" (click)="search()">
查询
{{ locale["query"] }}
</button>
<button nz-button type="button" (click)="reset()">
{{ locale["reset"] }}
</button>
<button nz-button type="button" (click)="reset()">重置</button>
<ng-content></ng-content>
<a
*ngIf="nzxCollapse"
Expand Down
20 changes: 15 additions & 5 deletions components/configurable-query/configurable-query.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import {
Output,
QueryList,
SimpleChanges,
TemplateRef,
} from '@angular/core';

import { AbstractControl, FormBuilder, FormGroup } from '@angular/forms';

import { NzJustify } from 'ng-zorro-antd/grid';
import { Subject, takeUntil } from 'rxjs';
import { ControlDirective } from './control.directive';
import { NzxQueryParams, NzxQueryControlOptions } from './type';
import { isArray } from 'ng-zorro-antd-extension/util';
import { NzxQueryControlOptions, NzxQueryParams } from './type';
import { NzI18nService } from 'ng-zorro-antd/i18n';
import { NzxQueryI18nInterface } from 'ng-zorro-antd-extension/i18n';

/**
* 查询组件
Expand Down Expand Up @@ -74,13 +74,15 @@ export class NzxConfigurableQueryComponent
}

get collapseText() {
return this.isCollapse ? '展开' : '收起';
return this.isCollapse ? this.locale.expand : this.locale.collapse;
}

get collapseIcon() {
return this.isCollapse ? 'down' : 'up';
}

locale!: NzxQueryI18nInterface;

/**是否展开状态*/
private isCollapse = true;
private _queryParams: NzxQueryParams = {};
Expand All @@ -92,7 +94,11 @@ export class NzxConfigurableQueryComponent
@ContentChildren(ControlDirective, { descendants: true })
controlTemplateList!: QueryList<ControlDirective>;

constructor(private fb: FormBuilder, private cd: ChangeDetectorRef) {
constructor(
private i18n: NzI18nService,
private fb: FormBuilder,
private cd: ChangeDetectorRef
) {
this.queryForm = this.fb.group({});
}

Expand All @@ -107,6 +113,10 @@ export class NzxConfigurableQueryComponent
}

ngOnInit(): void {
this.i18n.localeChange.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.locale = this.i18n.getLocaleData('Query');
this.cd.markForCheck();
});
this.queryForm.valueChanges
.pipe(takeUntil(this.destroy$))
.subscribe((val) => {
Expand Down
2 changes: 2 additions & 0 deletions components/configurable-query/configurable-query.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select';

import { NzxConfigurableQueryComponent } from './configurable-query.component';
import { ControlDirective } from './control.directive';
import { NzI18nModule } from 'ng-zorro-antd/i18n';

@NgModule({
declarations: [NzxConfigurableQueryComponent, ControlDirective],
Expand All @@ -26,6 +27,7 @@ import { ControlDirective } from './control.directive';
NzSelectModule,
NzDatePickerModule,
NzIconModule,
NzI18nModule,
],
exports: [ControlDirective, NzxConfigurableQueryComponent],
})
Expand Down
6 changes: 6 additions & 0 deletions components/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

export * from './public-api';
9 changes: 9 additions & 0 deletions components/i18n/languages/en_US.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
locale: 'en',
Query: {
query: 'query',
reset: 'reset',
expand: 'expand',
collapse: 'collapse',
},
};
9 changes: 9 additions & 0 deletions components/i18n/languages/zh_CN.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
locale: 'zh-cn',
Query: {
query: '查询',
reset: '重置',
expand: '展开',
collapse: '收起',
},
};
5 changes: 5 additions & 0 deletions components/i18n/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"lib": {
"entryFile": "public-api.ts"
}
}
6 changes: 6 additions & 0 deletions components/i18n/nz-i18n.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface NzxQueryI18nInterface {
query: string;
reset: string;
expand: string;
collapse: string;
}
4 changes: 4 additions & 0 deletions components/i18n/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './nz-i18n.interface';

export { default as nzx_en_US } from './languages/en_US';
export { default as nzx_zh_CN } from './languages/zh_CN';
8 changes: 7 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NzIconModule } from 'ng-zorro-antd/icon';
import { NzConfig, NZ_CONFIG } from 'ng-zorro-antd/core/config';
import { NzxConfig, NZX_CONFIG } from 'ng-zorro-antd-extension/core/config';
import { NzxAclModule } from 'ng-zorro-antd-extension/acl';
import { nzx_zh_CN } from 'ng-zorro-antd-extension/i18n';

registerLocaleData(zh);

Expand All @@ -27,6 +28,11 @@ const ngZorroExtensionConfig: NzxConfig = {
},
};

const customLanguagePack = {
zh_CN,
...nzx_zh_CN,
};

@NgModule({
declarations: [],
imports: [
Expand All @@ -39,7 +45,7 @@ const ngZorroExtensionConfig: NzxConfig = {
],
providers: [
...DOCGENI_SITE_PROVIDERS,
{ provide: NZ_I18N, useValue: zh_CN },
{ provide: NZ_I18N, useValue: customLanguagePack },
{ provide: NZ_CONFIG, useValue: ngZorroConfig },
{ provide: NZX_CONFIG, useValue: ngZorroExtensionConfig },
],
Expand Down

0 comments on commit 0e7181b

Please sign in to comment.