Skip to content

Add Brazilian Portuguese (pt) and move hardcoded UI strings to translations - #119

Open
jusales3270 wants to merge 1 commit into
fleetbase:mainfrom
jusales3270:feat/pt-br-translation
Open

jusales3270 wants to merge 1 commit into
fleetbase:mainfrom
jusales3270:feat/pt-br-translation

Conversation

@jusales3270

Copy link
Copy Markdown

What

  • Moves the hardcoded English UI strings of the current app to translation keys in translations/en.json, namespaced by screen or component. This covers screens, components, navigation headers and tab labels, contexts, hooks and utils. src/legacy is untouched. The English text is kept exactly as it was, so the English UI does not change.
  • Adds translations/pt.json, a complete Brazilian Portuguese translation. It is registered in src/utils/localize.js and listed in the default availableLocales. The default locale is still en.
  • Adds 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. BottomSheetSelect gets an optional formatLabel prop so IssueForm and FuelReportForm can use it.
  • LanguageContext applies the stored locale before the first render. react-native-i18n sets I18n.locale to the device language on load, which would otherwise leak into the first render once a second language exists.
  • Adds the missing common.storefront key used by SetupWarningScreen.
  • __tests__/LocationTrackingLifecycle-test.js mocks utils/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 pt rather than pt-BR. language-name-map only knows ISO 639-1 codes: getLangNameFromCode('pt-BR') is undefined, so the language picker would show no name. i18n-js fallbacks resolve a pt-BR device locale to pt.

How to test

  1. Run yarn install && yarn test. All suites pass (5/5, 10 tests).
  2. Run the app in English and check that the screens look unchanged: login, orders list, order detail, activity update, POD, reports, chat and account.
  3. Go to Account → Language → "Português". Labels, buttons, toasts, alerts, the tab bar, statuses, and issue and fuel form options switch to Portuguese. Switching back to English restores the original text.
  4. Optionally, build with DEFAULT_LOCALE=pt to start in Portuguese.

Every key referenced in src (excluding src/legacy) exists in both en.json and pt.json. The two files have the same 477 keys and the same placeholders.

Not in scope

  • Server-provided text (activity names and details, proof remarks, custom fields).
  • Date formats. Using a date-fns ptBR locale would be a natural follow-up.
  • src/legacy, and screens and components that are not routed or not used.

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant