Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for More Specific Locale Codes (e.g., en-US, zh-TW) #2417

Closed
PeterDaveHello opened this issue Oct 12, 2023 · 4 comments · Fixed by #2418
Closed

Support for More Specific Locale Codes (e.g., en-US, zh-TW) #2417

PeterDaveHello opened this issue Oct 12, 2023 · 4 comments · Fixed by #2418
Assignees
Labels
enhancement New feature or request

Comments

@PeterDaveHello
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The current locale support only includes two-letter language codes like en and zh. This doesn't account for more specific locale codes such as en-US, zh-CN, or zh-TW.

Describe the solution you'd like
I would like the project to extend its locale support to include more specific locale codes. This would make the application more versatile and better suited for international audiences.

Additional context
I am looking forward to this feature being implemented and would be happy to provide a zh-TW translation to supplement the existing zh (which is actually zh-CN).

@PeterDaveHello PeterDaveHello added the enhancement New feature or request label Oct 12, 2023
@PeterDaveHello
Copy link
Contributor Author

I've prepared a patch that might help solve this issue as below. Please let me know if you would like to take a look, and maybe I can submit a pull request for review?

diff --git a/assets/modules/i18n.ts b/assets/modules/i18n.ts
index 2d2cb1b..52ea64a 100644
--- a/assets/modules/i18n.ts
+++ b/assets/modules/i18n.ts
@@ -10,9 +10,15 @@ export const install = (app: App) => {
       },
     ),
   );
+
+  const userLang = navigator.language;
+  const shortLang = userLang.slice(0, 2);
+
+  const locale = messages.hasOwnProperty(userLang) ? userLang : (messages.hasOwnProperty(shortLang) ? shortLang : 'en');
+
   const i18n = createI18n({
     legacy: false,
-    locale: navigator.language.slice(0, 2),
+    locale: locale,
     fallbackLocale: "en",
     messages,
   });

@amir20
Copy link
Owner

amir20 commented Oct 12, 2023

Yes please send a PR. You don't need to provide EN. It's already set as fallback.

I am away this week will check Monday.

Thanks!

@amir20
Copy link
Owner

amir20 commented Oct 12, 2023

Also try reading https://kazupon.github.io/vue-i18n/guide/fallback.html#explicit-fallback-with-decision-maps. It might be better solution.

PeterDaveHello added a commit to PeterDaveHelloKitchen/dozzle that referenced this issue Oct 12, 2023
@PeterDaveHello
Copy link
Contributor Author

Sent here: #2418, thanks.

amir20 pushed a commit that referenced this issue Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants