@gravity-ui/i18n-cli (英语)
-
为项目提供i18n配置
-
规定
i18n-cli用于管理工程中语言文件的命令.
项目设置
-
安装软件包 :
npm i -D @gravity-ui/i18n-cli -
创建配置文件
i18n.config.ts在项目根中 :import {defineConfig} from '@gravity-ui/i18n-cli/config'; export default defineConfig({ allowedLocales: ['ru', 'en', 'ru-kz', 'en-kz'] as const, fallbackLocales: { 'ru-kz': 'ru', 'en-kz': 'en', }, defaultFallback: 'en', clientIntlModule: { path: 'src/shared/i18n/intl.ts', alias: '@shared/i18n', }, }); -
导入 i18n 库实例中的配置( i18n- react and i18n- node)
import {createIntl} from '@gravity-ui/i18n-react'; import i18nConfig from '../../../i18n.config'; const {allowedLocales, fallbackLocales, defaultFallback} = i18nConfig; export const intl = createIntl({ allowedLocales, fallbackLocales, defaultFallback, });
图标
create-keys
检查提供的文件/目录中缺少密钥的呼叫,并将其添加到 i18n.ts 文档.
运行一个文件
npx i18n-cli create-keys src/ui/SomeComponent/SomeComponent.tsx
运行目录中的所有文件
npx i18n-cli create-keys src/ui/ComponentDirectory
find-unused
从指定的目录开始对未使用的密钥进行回溯搜索 .
关于未用密钥的报告
npx i18n-cli find-unused src/ui/SomeComponent
删除未使用的密钥
npx i18n-cli find-unused -d src/ui/SomeComponent
配置选项
允许本地
类型 : string[]
在项目中允许本地人.
{
allowedLocales: ['ru', 'en'] as const,
}
后退本地语言
给定地方的倒计时。 详情请查阅: i18n- 核心数。 。 。 .
默认返回
默认倒计时。 如果没有找到更高的优先级,则使用。 更多进去 i18n- 核心数。 。 。 .
客户端 Intl 模块
客户端的库实例位置 i18n 反应 在项目.
{
clientIntlModule: {
// Path to the module with intl library instance
path: 'src/ui/shared/i18n.ts',
// TypeScript alias of the module with intl library instance
alias: '@shared/i18n';
}
}
服务器Intl模块
服务器侧库实例位置 i18n-节点 在项目.
{
serverIntlModule: {
// Path to the module containing the intl library instance
path: 'src/server/utils/i18n.ts',
// TypeScript alias of the module containing the intl library instance
alias: undefined,
// Regular expressions that determine if a module belongs to the server-side
pathMatchers: [/src\/server\/.+$/]
}
}