frontend/packages/arch/resources/studio-i18n-resource/README.md
Comprehensive internationalization (i18n) resource adapter for Coze Studio applications
This package provides a centralized internationalization resource adapter containing localized strings and type definitions for Coze Studio applications. It supports multiple languages and provides type-safe access to translation keys with parameter interpolation.
en) and Simplified Chinese (zh-CN)dl-i18n commandReactNode parameter typesThis package is part of the Coze Studio monorepo and should be installed via Rush:
# Add to your package.json dependencies
{
"dependencies": {
"@coze-studio/studio-i18n-resource-adapter": "workspace:*"
}
}
# Install dependencies
rush update
import {
localeEn,
localeZhCN,
defaultConfig,
type I18nKeysHasOptionsType,
type I18nKeysNoOptionsType
} from '@coze-studio/studio-i18n-resource-adapter';
// Use individual locale data
console.log(localeEn.AddSuccessToast); // Access English translation
console.log(localeZhCN.AddSuccessToast); // Access Chinese translation
// Use default configuration object
const currentLocale = 'en';
const translations = defaultConfig[currentLocale].i18n;
import { defaultConfig } from '@coze-studio/studio-i18n-resource-adapter';
import i18n from 'i18next';
// Initialize with react-i18next
i18n.init({
resources: defaultConfig,
lng: 'en',
fallbackLng: 'en',
defaultNS: 'i18n',
interpolation: {
escapeValue: false
}
});
localeEnEnglish locale data object containing all translation strings.
import { localeEn } from '@coze-studio/studio-i18n-resource-adapter';
// Simple string access
const message = localeEn.account_login_success;
localeZhCNSimplified Chinese locale data object containing all translation strings.
import { localeZhCN } from '@coze-studio/studio-i18n-resource-adapter';
// Simple string access
const message = localeZhCN.account_login_success;
defaultConfigPre-configured object structure ready for use with i18n libraries.
import { defaultConfig } from '@coze-studio/studio-i18n-resource-adapter';
// Structure: { [locale]: { i18n: translations } }
const config = defaultConfig;
// config.en.i18n contains English translations
// config['zh-CN'].i18n contains Chinese translations
I18nKeysHasOptionsTypeUnion type of all translation keys that require parameters for interpolation.
import { type I18nKeysHasOptionsType } from '@coze-studio/studio-i18n-resource-adapter';
// Example keys that require parameters:
// - 'AddSuccessToast' (requires: { name: ReactNode })
// - 'Coze_token_body' (requires: { num: number })
// - 'account_merge_oauth_success2' (requires: { phone_number: string })
I18nKeysNoOptionsTypeUnion type of all translation keys that don't require parameters.
import { type I18nKeysNoOptionsType } from '@coze-studio/studio-i18n-resource-adapter';
// Example keys without parameters:
// - 'account_login_success'
// - 'bot_create_success'
// - 'workflow_save_success'
I18nOptionsMapInterface mapping each parameterized translation key to its required parameters.
import { type I18nOptionsMap } from '@coze-studio/studio-i18n-resource-adapter';
// Type-safe parameter access
type AddSuccessParams = I18nOptionsMap['AddSuccessToast']; // { name: ReactNode }
type TokenBodyParams = I18nOptionsMap['Coze_token_body']; // { num: ReactNode }
LocaleDataType definition for the structure of locale data objects.
import { type LocaleData } from '@coze-studio/studio-i18n-resource-adapter';
// Use for typing custom locale objects
const customLocale: LocaleData = {
// ... your translation keys
};
import { localeEn, type I18nOptionsMap } from '@coze-studio/studio-i18n-resource-adapter';
// With react-i18next
import { useTranslation } from 'react-i18next';
function MyComponent() {
const { t } = useTranslation();
// Type-safe parameter usage
const successMessage = t('AddSuccessToast', {
name: 'My Bot'
} satisfies I18nOptionsMap['AddSuccessToast']);
const tokenMessage = t('Coze_token_body', {
num: 100
} satisfies I18nOptionsMap['Coze_token_body']);
return <div>{successMessage}</div>;
}
The locale files and type definitions are auto-generated. To update them:
# Run the i18n download command
pnpm dl-i18n
This will:
en.json and zh-CN.json fileslocale-data.d.ts type definitionsindex.ts export fileTo add support for additional languages:
src/locales/src/index.tsdefaultConfig object to include the new localepnpm dl-i18nsrc/
āāā index.ts # Main exports and default configuration
āāā locale-data.d.ts # Auto-generated TypeScript definitions
āāā locales/
āāā en.json # English translations (~13K+ strings)
āāā zh-CN.json # Chinese translations (~14K+ strings)
react ~18.2.0 - Required for ReactNode type supportreact-dom ~18.2.0 - React DOM integration@coze-arch/eslint-config - Linting configuration@coze-arch/ts-config - TypeScript configuration@coze-arch/vitest-config - Testing configuration@types/node ^18 - Node.js type definitionsThis package is part of the Coze Studio monorepo and follows the same licensing terms as the main project.
Note: This package is automatically generated and maintained. Direct modifications to locale files or type definitions will be overwritten during the next dl-i18n command execution.