This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
import { I18n, type I18nLanguage } from '@flowgram.ai/i18n';
|
||||
import { definePluginCreator } from '@flowgram.ai/core';
|
||||
|
||||
export interface I18nPluginOptions {
|
||||
locale?: string;
|
||||
/**
|
||||
* use `locale` instead
|
||||
* @deprecated
|
||||
*/
|
||||
localLanguage?: string;
|
||||
/**
|
||||
* if missingStrictMode is true
|
||||
* expect(I18n.t('Unknown')).toEqual('[missing "en-US.Unknown" translation]')
|
||||
* else
|
||||
* expect(I18n.t('Unknown')).toEqual('Unknown')
|
||||
*/
|
||||
missingStrictMode?: boolean;
|
||||
languages?: I18nLanguage[] | Record<string, Record<string, any>>;
|
||||
onLanguageChange?: (languageId: string) => void;
|
||||
}
|
||||
/**
|
||||
* I18n Plugin
|
||||
*/
|
||||
export const createI18nPlugin = definePluginCreator<I18nPluginOptions>({
|
||||
onInit: (ctx, _opts) => {
|
||||
if (_opts.onLanguageChange) {
|
||||
ctx.playground.toDispose.push(I18n.onLanguageChange(_opts.onLanguageChange));
|
||||
}
|
||||
if (_opts.languages) {
|
||||
if (Array.isArray(_opts.languages)) {
|
||||
I18n.addLanguages(_opts.languages);
|
||||
} else {
|
||||
I18n.addLanguages(
|
||||
Object.keys(_opts.languages).map((key) => ({
|
||||
languageId: key,
|
||||
contents: (_opts.languages as any)![key],
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_opts.locale || _opts.localLanguage) {
|
||||
I18n.locale = (_opts.locale || _opts.localLanguage)!;
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
export { I18n, type I18nLanguage } from '@flowgram.ai/i18n';
|
||||
export { createI18nPlugin, type I18nPluginOptions } from './create-i18n-plugin';
|
||||
Reference in New Issue
Block a user