feat: 为插件提供翻译机制

pull/13/head
moonrailgun 4 years ago
parent cb0bf69983
commit a6b309c089

@ -58,6 +58,18 @@ export const t: TFunction = (
}
};
/**
*
* @example
* localTrans({zh-CN: '你好', en-US: 'Hello'});
*
* @param trans
*/
export function localTrans(trans: Record<AllowedLanguage, string>) {
const lang = i18next.language as AllowedLanguage;
return trans[lang] ?? trans['zh-CN'] ?? trans['en-US'];
}
/**
* i18next
*/

@ -43,7 +43,7 @@ export { useColorScheme } from './contexts/ColorSchemeContext';
export { getDMConverseName } from './helper/converse-helper';
// i18n
export { t, setLanguage, useTranslation } from './i18n';
export { t, localTrans, setLanguage, useTranslation } from './i18n';
export { Trans } from './i18n/Trans';
export { useLanguage } from './i18n/language';

@ -1,6 +1,5 @@
{
"compilerOptions": {
"rootDir": "./src",
"baseUrl": "./src",
"esModuleInterop": true,
"jsx": "react",

@ -10,4 +10,8 @@ export {
} from '@/routes/Main/Content/Group/utils';
export { openModal, ModalWrapper, useModalContext } from '@/components/Modal';
export { getGlobalState } from '@/utils/global-state-helper';
export { getCachedUserInfo, getCachedConverseInfo } from 'tailchat-shared';
export {
getCachedUserInfo,
getCachedConverseInfo,
localTrans,
} from 'tailchat-shared';

Loading…
Cancel
Save