refactor: move from next-international to next-intl (#1368)
* refactor: move from next-international to next-intl * refactor: restructure translation package, * chore: change i18n-allay framework to next-intl * fix: add missing bold html tag to translation * fix: format issue * fix: address deepsource issues * fix: remove international-types dependency * fix: lint and typecheck issues * fix: typecheck issue * fix: typecheck issue * fix: issue with translations
This commit is contained in:
19
packages/translation/src/client/index.ts
Normal file
19
packages/translation/src/client/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
"use client";
|
||||
|
||||
import { useMessages, useTranslations } from "next-intl";
|
||||
|
||||
import type { TranslationObject } from "../type";
|
||||
|
||||
export { useChangeLocale } from "./use-change-locale";
|
||||
export { useCurrentLocale } from "./use-current-locale";
|
||||
|
||||
export const { useI18n, useScopedI18n } = {
|
||||
useI18n: useTranslations,
|
||||
useScopedI18n: useTranslations,
|
||||
};
|
||||
|
||||
export const { useI18nMessages } = {
|
||||
useI18nMessages: () => useMessages() as TranslationObject,
|
||||
};
|
||||
|
||||
export { useTranslations };
|
||||
25
packages/translation/src/client/use-change-locale.ts
Normal file
25
packages/translation/src/client/use-change-locale.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useTransition } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
|
||||
import type { SupportedLanguage } from "../config";
|
||||
import { useCurrentLocale } from "./use-current-locale";
|
||||
|
||||
export const useChangeLocale = () => {
|
||||
const currentLocale = useCurrentLocale();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
return {
|
||||
changeLocale: (newLocale: SupportedLanguage) => {
|
||||
if (newLocale === currentLocale) {
|
||||
return;
|
||||
}
|
||||
|
||||
startTransition(() => {
|
||||
router.replace(`/${newLocale}/${pathname}`);
|
||||
});
|
||||
},
|
||||
isPending,
|
||||
};
|
||||
};
|
||||
5
packages/translation/src/client/use-current-locale.ts
Normal file
5
packages/translation/src/client/use-current-locale.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { useLocale } from "next-intl";
|
||||
|
||||
import type { SupportedLanguage } from "../config";
|
||||
|
||||
export const useCurrentLocale = () => useLocale() as SupportedLanguage;
|
||||
Reference in New Issue
Block a user