Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(abc:st): add i18n in pop #1874

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/abc/st/st-column-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export class STColumnSource {
pop.condition = () => false;
}

if (this.i18nSrv) {
if (pop.titleI18n) pop.title = this.i18nSrv.fanyi(pop.titleI18n);
if (pop.okTextI18n) pop.okText = this.i18nSrv.fanyi(pop.okTextI18n);
if (pop.cancelTextI18n) pop.cancelText = this.i18nSrv.fanyi(pop.cancelTextI18n);
}

i.pop = pop;
}

Expand Down
6 changes: 6 additions & 0 deletions packages/abc/st/st.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,8 @@ export interface STColumnButtonPop<T extends STData = any> {
*/
title?: string;

titleI18n?: string;

/**
* Popover trigger mode, default: `click`
*/
Expand Down Expand Up @@ -955,11 +957,15 @@ export interface STColumnButtonPop<T extends STData = any> {
*/
cancelText?: string;

cancelTextI18n?: string;

/**
* Text of the Confirm button
*/
okText?: string;

okTextI18n?: string;

/**
* Button `type` of the Confirm button
*/
Expand Down
17 changes: 12 additions & 5 deletions packages/abc/st/test/base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export function genModule<T extends TestComponent>(
other: {
template?: string;
i18n?: boolean;
i18nIgnoreOverride?: boolean;
minColumn?: boolean;
providers?: NzSafeAny[];
createComp?: boolean;
Expand All @@ -109,15 +110,21 @@ export function genModule<T extends TestComponent>(
STModule,
DelonLocaleModule
];
const providers = [
const providers: NzSafeAny[] = [
provideNoopAnimations(),
provideHttpClient(),
provideHttpClientTesting(),
{
provideHttpClientTesting()
// {
// provide: ALAIN_I18N_TOKEN,
// useClass: MockI18NServiceFake
// }
];
if (other.i18nIgnoreOverride !== true) {
providers.push({
provide: ALAIN_I18N_TOKEN,
useClass: MockI18NServiceFake
}
];
});
}
if (other.providers!.length > 0) {
providers.push(...other.providers!);
}
Expand Down
18 changes: 18 additions & 0 deletions packages/abc/st/test/st.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1648,4 +1648,22 @@ describe('abc: st', () => {
expect(i18nSrv.fanyi).toHaveBeenCalled();
}));
});
describe('[i18n without fake]', () => {
let curLang = 'en';
beforeEach(() => {
page = genModule(TestComponent, { i18n: true, i18nIgnoreOverride: true })!;
refAssign();
});
it(`should be auto i18n in pop type`, fakeAsync(() => {
curLang = 'zh';
i18nSrv.use(curLang, { a: '一', b: '二', c: '三' });
const columns: STColumn[] = [
{
title: '',
buttons: [{ text: 'pop', pop: { titleI18n: 'a', okTextI18n: 'b', cancelTextI18n: 'c' } }]
}
];
page.updateColumn(columns).click('.st__btn-text').cd().expectElContent('.ant-popover-message-title', '一');
}));
});
});
Loading