From 646f3a8d044a634f68058c380bc83c969b207bfa Mon Sep 17 00:00:00 2001 From: jack zhang <1098626505@qq.com> Date: Mon, 29 Jul 2024 17:51:24 +0800 Subject: [PATCH] fix: i18n plugin utils (#4962) --- .../core/cli/templates/plugin/src/client/locale.ts | 12 ++++++------ packages/core/client/src/i18n/i18n.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/core/cli/templates/plugin/src/client/locale.ts b/packages/core/cli/templates/plugin/src/client/locale.ts index 2cf2a95584..acaee6a43d 100644 --- a/packages/core/cli/templates/plugin/src/client/locale.ts +++ b/packages/core/cli/templates/plugin/src/client/locale.ts @@ -1,12 +1,12 @@ -import { useTranslation } from 'react-i18next'; - // @ts-ignore import pkg from './../../package.json'; +import { useApp } from '@nocobase/client'; -export function usePluginTranslation() { - return useTranslation([pkg.name, 'client'], { nsMode: 'fallback' }); +export function useT() { + const app = useApp(); + return (str: string) => app.i18n.t(str, { ns: pkg.name }); } -export function generatePluginTranslationTemplate(key: string) { - return `{{t('${key}', { ns: ['${pkg.name}', 'client'], nsMode: 'fallback' })}}`; +export function tStr(key: string) { + return `{{t('${key}', { ns: '${pkg.name}', nsMode: 'fallback' })}}`; } diff --git a/packages/core/client/src/i18n/i18n.ts b/packages/core/client/src/i18n/i18n.ts index b0618a2a00..98b7d59020 100644 --- a/packages/core/client/src/i18n/i18n.ts +++ b/packages/core/client/src/i18n/i18n.ts @@ -37,7 +37,7 @@ i18n lng: 'en-US', // debug: true, defaultNS: 'client', - // fallbackNS: 'client', + fallbackNS: 'client', // backend: { // // for all available options read the backend's repository readme file // loadPath: '/api/locales/{{lng}}/{{ns}}.json',