summaryrefslogtreecommitdiff
path: root/i18n/index.ts
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-03-26 00:37:41 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-03-26 00:37:41 +0000
commite0dfb55c5457aec489fc084c4567e791b4c65eb1 (patch)
tree68543a65d88f5afb3a0202925804103daa91bc6f /i18n/index.ts
3/25 까지의 대표님 작업사항
Diffstat (limited to 'i18n/index.ts')
-rw-r--r--i18n/index.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/i18n/index.ts b/i18n/index.ts
new file mode 100644
index 00000000..c78ecd1e
--- /dev/null
+++ b/i18n/index.ts
@@ -0,0 +1,34 @@
+import { createInstance, Namespace, FlatNamespace, KeyPrefix } from 'i18next';
+import resourcesToBackend from 'i18next-resources-to-backend';
+import { initReactI18next } from 'react-i18next/initReactI18next';
+import { FallbackNs } from 'react-i18next';
+
+import { getOptions } from '@/i18n/settings';
+
+const initI18next = async (lng: string, ns: string | string[]) => {
+ const i18nInstance = createInstance();
+ await i18nInstance
+ .use(initReactI18next)
+ .use(
+ resourcesToBackend(
+ (language: string, namespace: string) =>
+ import(`./locales/${language}/${namespace}.json`)
+ )
+ )
+ .init(getOptions(lng, ns));
+ return i18nInstance;
+};
+
+export async function useTranslation<
+ Ns extends FlatNamespace,
+ KPrefix extends KeyPrefix<FallbackNs<Ns>> = undefined,
+>(lng: string, ns?: Ns, options: { keyPrefix?: KPrefix } = {}) {
+ const i18nextInstance = await initI18next(
+ lng,
+ Array.isArray(ns) ? (ns as string[]) : (ns as string)
+ );
+ return {
+ t: i18nextInstance.getFixedT(lng, ns, options.keyPrefix),
+ i18n: i18nextInstance,
+ };
+} \ No newline at end of file