yarn
安装 glotstackyarn install glotstack
<GlotstackProvider initialLocale='en-US' importMethod={importMethod}>
<YourApp/>
</GlotstackProvider>
importMethod
的说明yarn glotstack get-translations
context
确保翻译准确匹配您的意图。想用 YAML 文件请查看 关于 YAML。const { t } = useGlotstack()
<>
{t('YourKey', {
assigns: {
Component: <Component prop="f"></Component>,
insertNode: <Icon name="icon-set"/>,
mdash: <>—</>
another: <>{t('OtherKey', {locale: 'en-US'})}
},
})}
</>
assigns
选项将任意 React.Node
替换到翻译中。只需在 assigns 中传入相应组件名,即可内联使用 <Component>something</Component>
标记 —— 这在不想新增翻译键时非常实用。也可以直接使用 {{substitution}}
标记替换任意节点。YourKey:
value: |
This is an example source text. We want to <Component>do this</Component.
We also want to demonstrate {{insertNode}} and {{mdash}}.
We can even nest other translated things {{another}}.
yarn glotstack extract-translations
CLI
自动提取您用母语编写的源文件字符串。这样,如果愿意,您甚至可以完全忽略翻译文件。继续像以前一样编写代码,glotstack 会处理其余工作。