Repository navigation
Frontend: add Indonesian/English UI with language selector and location-based default - #29
Merged
Merged
Conversation
…location-based default
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The UI is now available in Indonesian and English. Users switch with an ID / EN selector. The first visit picks the language from the visitor's location: Indonesian in Indonesia, English everywhere else.
How the language is chosen
localStorageand always wins.CF-IPCountryheader and passes it to the SPA as ageo_countrycookie.ID→ Indonesian, any other country → English. The language is correct on the first render, with no extra request.XX): a browser time zone ofAsia/Jakarta,Asia/Pontianak,Asia/MakassarorAsia/Jayapura→ Indonesian, otherwise English.nginx details (
frontend/nginx.conf)/api,/wsor static files. ASet-Cookieon assets would stop Cloudflare from caching them. The check uses$request_uri, becausetry_filesrewrites$urito/index.html.add_headeris at server level next to the existing security headers. An empty value sends no header.Implementation
src/i18n/: a small in-house i18n module, no new dependencies.useI18n()returnst,lang,localeandsetLang. The language lives in a zustand store, so switching re-renders the app.t()is for code outside components: theutils/files.tsalert, and event listeners/timers inExamRunner.{name}placeholders.src/i18n/messages/: one namespace per page, pluscommon,navandauth.defineMessages()makes a key present in only one language a type error, sonpm run buildfails on untranslated text.LanguageSwitcheris placed in:title/aria-label/alt,alert/confirm, error fallbacks, status and role badges, and option labels.id-ID/en-US) instead of the browser default.Not in this PR
response.data.message) are shown as the backend returns them, which is mixed Indonesian and English. A follow-up could sendAccept-Languageand localize them on the server.index.htmlmetadata. The meta description and Open Graph tags stay as they are.<html lang>is set at runtime.Deployment notes
proxy_pass.Testing
tsc -bandvite buildpass.oxlint: no new warnings. The 4 existing warnings inExamMonitor/MaterialsListare unchanged.XX, malformed cookie, and Indonesian / non-Indonesian time zones./login:geo_country=IDwith Berlin time zone → Indonesiangeo_country=USwith Jakarta time zone → Englishcurl -sI -H 'CF-IPCountry: ID' http://localhost/loginreturnsSet-Cookie: geo_country=ID, and/assets/*//api/*responses do not.