Add i18n support #5
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "basic-scaffolding-frontend-lingui"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds i18n support with lingui
Once you've added a string, run
npm run extractto extract the strings, translate them in./i18n/locales/sv/messages.po. If running vite, the messages should be compiled automatically, otherwise runnpm run compile.Overall it looks good, some minor questions in individual comments.
One thing I'm also wondering about is moving the i18n stuff to App.tsx instead of main.tsx. In my mind the App component is responsible for loading all the context required for the application itself, such as the profile, i18n, preferences, or anything else. What is your view on main.tsx vs App.tsx?
@ -7,3 +7,3 @@export default tseslint.config({ ignores: ["dist"] },{ ignores: ["dist", "src/i18n/locales/**/*.ts"] },Do we need this since the generated
.tsfiles have/*eslint-disable*/at the start?Otherwise you get the warning
Unused eslint-disable directive (no problems were reported)when runnningnpm run lint@ -13,0 +12,4 @@"preview": "vite preview","extract": "lingui extract","extract-clean": "lingui extract --clean","compile": "lingui compile --typescript"Need instructions in the readme what these commands do and what the expected workflow is when adding/translating new content.
@ -0,0 +1,9 @@const supportedLocales = ["sv", "en"];export function getDefaultLocale(): string {const lang = navigator.language.split("-")[0]; // "en-US" -> "en"Should maybe iterate over
navigator.languagesinstead to find the most preferred locale? If a user sends "Accept-Language: de-DE, en-US, sv-SE" they will get Swedish instead of English since German isn't available.Also should we maybe default to English if no available language is found instead of Swedish?
I agree that we should interate over
navigator.languagesinstead.Regarding defaulting to english if no language is found, very good question. We are Swedish public agency, most outward facing systems default to Swedish, but on the other hand, if they don't have Swedish as an accepted language, there's probably a high likelyhood that they are non-Swedish speakers. I think there's a strong case here to default to English.
Based on that I'd say defaulting to English makes sense and adhering to the "Accept-Language" header is just nice for users.
I put the i18n initialization stuff in main.tsx because we need to have it in place before we have a profile and display the splash screen, I thought it felt like a natural flow of things, separating bootstrapping the app with rendering and default locale into main.tsx. But I don't have a strong opinion on it. Your approach would add additional logic to App.tsx which may be fine.
I just have some vision in my head of App.tsx looking like
But maybe that adds way too much logic above it to accomplish everything. Eh it's fine, we can always refactor later once we know more.
One final question, is it the
t(...)function one should use to show some feedback in a click handler/form submit scenario?Yes, that's the idea.
Running
npm run buildproduces no output.After discussions, we decided to more forward with something other than lingui
Pull request closed