Feat add i18n support (Multi-Language Support)
Summary
The main purpose of this pull request is to refactor the application's UI, removing static text to prepare it for multi-language support.
To achieve this, I have integrated the vue-i18n library, established the necessary infrastructure, and fully dynamized the SetupUI.vue component. Thanks to this new foundation, adding new languages in the future will be as simple as adding a single translation file.
Technical Implementation
-
Installed
vue-i18nLibrary:- Added
vue-i18n@nextto the project dependencies, which is fully compatible with the Vue 3 structure.
- Added
-
Created Translation Infrastructure:
- Created a new
src/renderer/locales/directory to host translation files. - Migrated all existing UI text from
SetupUI.vueinto a key-value format inen.json. This file now serves as the primary template for all future languages.
- Created a new
-
Configured
i18n.ts:- Created a central configuration file at
src/renderer/i18n.ts. This file:- Loads the translation files (like
en.json). - Automatically sets the app's starting language based on the user's browser language.
- Sets English (
fallbackLocale: 'en') as the default language if the browser's language is not supported.
- Loads the translation files (like
- Created a central configuration file at
-
Integrated into Vue App:
- The
i18ninstance was integrated into the app's main entry point (src/renderer/main.ts) using the.use(i18n)directive, making translation functions available globally.
- The
-
Converted UI to Dynamic Translations:
- All hard-coded text (headers, paragraphs, button labels, error messages, etc.) in
SetupUI.vuewas replaced with thet('key')function. - Dynamic text (e.g., "Detected: 4 cores") and pluralization (e.g., "Core/Cores") are now correctly managed using
vue-i18n's parameters and pluralization features.
- All hard-coded text (headers, paragraphs, button labels, error messages, etc.) in
How to Add a New Language
As requested, I am only leaving the English language pack as the base. To add a new language (e.g., German - de), you just need to follow these steps:
-
Create a new file: Copy
en.jsonand createde.jsonin thesrc/renderer/locales/directory. -
Translate the values: Open
de.jsonand translate the values from English to German, using the keys fromen.jsonas a reference. -
Register the language: Open
src/renderer/i18n.tsand make these two small changes:- Add the import line:
import de from './locales/de.json'; - Add the language to the
messagesobject:de,
- Add the import line:
I think you should translate the comments in createI18n
I think you should translate the comments in
createI18n
Thanks for feedback. I had accidentally left some Turkish comments in my code. I've just pushed an update.
Added support for 5 different languages.
Nice addition, thank you for your time working on this!
I'll be converting this PR to a draft to reflect that it's still in progress, but great job so far!