目的
为d2前端Apps提供通化支持.
安装
yarn add @dhis2/d2-i18n
提取和生成地语字符串
采掘和生成由 build 财务报告和审定财务报表 start 命令编号 @dhis2/cli-app-scripts:您应该知道可以选择,它们也可以独立于建筑物之外运行:
yarn d2-app-scripts i18n extract
yarn d2-app-scripts i18n generate
在 App 代码中
在开发/建设阶段 弧度/地点 将创建目录。 它将包括国际化的必要设置、日期/时间、日历等。 它是自动生成的,所以请不要更新,任何更改都会丢失.
在最顶端 标准/指数.js (假设这是你App的主要入口). 增加以下内容:,
import './locales'
更改用户区域
创建函数 本地变化 财务报告和审定财务报表 是 LangRTL 语言 现改为: 您应该在 App 加载阶段调用此函数 .
function isLangRTL(code) {
const langs = ['ar', 'fa', 'ur']
const prefixed = langs.map(c => `${c}-`)
return (
langs.includes(code) ||
prefixed.filter(c => code.startsWith(c)).length > 0
)
}
function changeLocale(locale) {
moment.locale(locale)
i18n.changeLanguage(locale)
document.documentElement.setAttribute(
'dir',
isLangRTL(locale) ? 'rtl' : 'ltr'
)
}
翻译
传送要翻译的字符串 i18n.t (单位:千美元) 函数如下.
import i18n from '@dhis2/d2-i18n'
i18n.t('translation string')
A. 背景情况
过 上下文 属性在第二个参数至 i18n.t
i18n.t('hello world', {
context: 'a customary string to welcome a new born developer',
})
提取点 将自动生成 毫斯克特克特 字段之前 缩写 在en.pot文件中,使翻译者有更好的翻译上下文.
msgctxt "a customary string to welcome a new born developer"
msgid "hello world"
msgstr ""
.吉提格诺尔
附加目录 弧度/地点 在结尾。 因为在Dev/建设阶段 弧度/地点 是自动生成的.
升级
线条
yarn upgrade --scope @dhis2
.travis.yml (英语)
单位 .travis.yml (英语) 在构建/部署步骤之前添加 yarn localize
页:1
- 我们不用 反应- i18next 因为当 ASCII 和 RTL 字符混合时处理文本编辑器中的光标无法编辑 。 一些ASCII字符将光标移到一行一端,而RTL字符则将光标移到一行一端. 使用 RTL 语言字符串中的变量不起作用, 因为第一个 {{ 翻译时可能输入正确, 但我们要输入结尾序列时 }} 光标最终会出现在错误的地方,因此无法翻译.
报告问题
深链接 :