Repository navigation
Add Brazilian Portuguese (pt) and move hardcoded UI strings to translations - #119
Open
jusales3270 wants to merge 1 commit into
Open
jusales3270 wants to merge 1 commit into
jusales3270 wants to merge 1 commit into
Conversation
Move the hardcoded English UI strings of the current app (screens,
components, navigation headers/tab labels, contexts, hooks and utils;
src/legacy untouched) to translation keys, and add a complete
Brazilian Portuguese translation.
- en.json: new keys namespaced by screen/component, holding the exact
English text shown today, so the English UI does not change.
- pt.json: full Brazilian Portuguese translation of every key. The
locale code is "pt" because language-name-map only knows ISO 639-1
codes (getLangNameFromCode("pt-BR") is undefined, so the picker would
show an empty name); i18n-js fallbacks still resolve a "pt-BR" device
locale to "pt".
- localize.js: register pt, add it to the default availableLocales
(default locale stays "en"), and add translateLabel() for dynamic
values (order/issue/fuel statuses, issue types and categories, POD
methods, units, color schemes). It only replaces the label when the
active locale has its own translation, otherwise it returns the
original label, so English output is identical.
- BottomSheetSelect: optional formatLabel prop (used by IssueForm and
FuelReportForm) and translated default placeholders.
- LanguageContext: apply the stored locale before the first render
instead of in an effect; react-native-i18n initializes I18n.locale to
the device language, which would otherwise leak into the first render
now that a second language exists.
- Existing en.json keys are unchanged; common.storefront was referenced
by SetupWarningScreen but missing, so it is added.
- LocationTrackingLifecycle test mocks utils/localize like the other
mocked utils.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
translations/en.json, namespaced by screen or component. This covers screens, components, navigation headers and tab labels, contexts, hooks and utils.src/legacyis untouched. The English text is kept exactly as it was, so the English UI does not change.translations/pt.json, a complete Brazilian Portuguese translation. It is registered insrc/utils/localize.jsand listed in the defaultavailableLocales. The default locale is stillen.translateLabel(scope, value, fallback)for labels that come from data: order, issue and fuel statuses and priorities, issue types and categories, POD methods, units and color scheme. It only replaces a label when the active locale has its own translation, so English output is identical.BottomSheetSelectgets an optionalformatLabelprop so IssueForm and FuelReportForm can use it.LanguageContextapplies the stored locale before the first render.react-native-i18nsetsI18n.localeto the device language on load, which would otherwise leak into the first render once a second language exists.common.storefrontkey used by SetupWarningScreen.__tests__/LocationTrackingLifecycle-test.jsmocksutils/localize, like the other utils it already mocks.Why
Drivers in Brazil need the app in Portuguese. This also makes the current app fully translatable, so another language only needs a new JSON file.
Locale code
The code is
ptrather thanpt-BR.language-name-maponly knows ISO 639-1 codes:getLangNameFromCode('pt-BR')is undefined, so the language picker would show no name. i18n-js fallbacks resolve apt-BRdevice locale topt.How to test
yarn install && yarn test. All suites pass (5/5, 10 tests).DEFAULT_LOCALE=ptto start in Portuguese.Every key referenced in
src(excludingsrc/legacy) exists in bothen.jsonandpt.json. The two files have the same 477 keys and the same placeholders.Not in scope
ptBRlocale would be a natural follow-up.src/legacy, and screens and components that are not routed or not used.🤖 Generated with Claude Code