From 80ff52017aee696c13826a8f211deb832b7b4f44 Mon Sep 17 00:00:00 2001 From: Moinul Moin Date: Mon, 1 Jan 2024 13:21:25 +0600 Subject: [PATCH 1/3] feat: :sparkles: return if newLocale is already set --- .../src/app/client/create-use-change-locale.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/next-international/src/app/client/create-use-change-locale.ts b/packages/next-international/src/app/client/create-use-change-locale.ts index d866050..2fbe9f4 100644 --- a/packages/next-international/src/app/client/create-use-change-locale.ts +++ b/packages/next-international/src/app/client/create-use-change-locale.ts @@ -31,6 +31,11 @@ export function createUseChangeLocale( } return function changeLocale(newLocale: LocalesKeys) { + if (newLocale === currentLocale) { + warn(`The locale '${newLocale}' is already set. Defined locales are: [${Object.keys(locales).join(', ')}].`); + return; + } + const importFnLocale = locales[newLocale as keyof typeof locales]; if (!importFnLocale) { From 0e4b02f9822dcd61df4b01cea03724a128b00adf Mon Sep 17 00:00:00 2001 From: Moinul Moin Date: Mon, 1 Jan 2024 13:21:25 +0600 Subject: [PATCH 2/3] feat: :sparkles: return if newLocale is already set --- .../src/app/client/create-use-change-locale.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next-international/src/app/client/create-use-change-locale.ts b/packages/next-international/src/app/client/create-use-change-locale.ts index 2fbe9f4..75475dd 100644 --- a/packages/next-international/src/app/client/create-use-change-locale.ts +++ b/packages/next-international/src/app/client/create-use-change-locale.ts @@ -32,7 +32,7 @@ export function createUseChangeLocale( return function changeLocale(newLocale: LocalesKeys) { if (newLocale === currentLocale) { - warn(`The locale '${newLocale}' is already set. Defined locales are: [${Object.keys(locales).join(', ')}].`); + warn(`The locale '${newLocale}' is already set`); return; } From a04ac74121cecf024149a959f1bd08de5129c1e6 Mon Sep 17 00:00:00 2001 From: Moinul Moin Date: Mon, 1 Jan 2024 14:49:35 +0600 Subject: [PATCH 3/3] refactor: :recycle: remove warning log --- .../src/app/client/create-use-change-locale.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/next-international/src/app/client/create-use-change-locale.ts b/packages/next-international/src/app/client/create-use-change-locale.ts index 75475dd..f5fb185 100644 --- a/packages/next-international/src/app/client/create-use-change-locale.ts +++ b/packages/next-international/src/app/client/create-use-change-locale.ts @@ -31,10 +31,7 @@ export function createUseChangeLocale( } return function changeLocale(newLocale: LocalesKeys) { - if (newLocale === currentLocale) { - warn(`The locale '${newLocale}' is already set`); - return; - } + if (newLocale === currentLocale) return; const importFnLocale = locales[newLocale as keyof typeof locales];