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
直接替換進翻譯中。只要你傳入正確的組件名稱,就可以在行內使用 <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 會幫你處理好一切。