Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(locales): move to using static file #1275

Merged
merged 1 commit into from
Mar 5, 2021

Conversation

LoneRifle
Copy link
Contributor

@LoneRifle LoneRifle commented Mar 4, 2021

Problem

We want to use a single codebase for several similar deployments, but
with different themes and copywriting text. To that end, we need resource strings
to be easily substitutable. As of now, they are implemented as a TypeScript module
webpacked into the bundle

Part of work for #777

Solution

Move translation resource strings to static file, so that we can easily
substitute such files for deployments using the Go.gov.sg codebase

  • npm install i18next-http-backend
  • app/assets/.../translation -> public/locales/.../translation.json
    • Make use of i18next's in-built nesting feature in lieu of the
      string interpolation were doing in the app/assets ts file
  • add i18next-http-backend to i18next bootstrap, so that we fetch
    translations from a static path instead of having it injected into
    the config
  • wait on i18next initialization before proceeding to render
  • FeatureListSliver - swop out <Trans> elements for i18next.t calls

Deploy Notes

New dependencies:

  • i18next-http-backend : backend that fetches translations from a defined path

@LoneRifle LoneRifle force-pushed the refactor/locales/static branch from e0ffdc8 to 63b6165 Compare March 4, 2021 06:14
Move translation resource strings to static file, so that we can easily
substitute such files for deployments using the Go.gov.sg codebase

- `npm install i18next-http-backend`
- `app/assets/.../translation` -> `public/locales/.../translation.json`
  - Make use of i18next's in-built nesting feature in lieu of the
    string interpolation were doing in the `app/assets` ts file
- add i18next-http-backend to i18next bootstrap, so that we fetch
  translations from a static path instead of having it injected into
  the config
- wait on i18next initialization before proceeding to render
- FeatureListSliver - swop out `<Trans>` elements for i18next.t calls
@LoneRifle LoneRifle force-pushed the refactor/locales/static branch from 63b6165 to 7462458 Compare March 4, 2021 11:15
Copy link
Member

@yong-jie yong-jie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the <Trans> is also used in LandingGraphicSliver.tsx. Do you also plan to migrate that to vanilla i18next? we might be able to remove react-i18next if that's the case

@LoneRifle
Copy link
Contributor Author

looks like the <Trans> is also used in LandingGraphicSliver.tsx. Do you also plan to migrate that to vanilla i18next? we might be able to remove react-i18next if that's the case

<Trans> is being used here to honour the style tags that are found in the resource strings.

@yong-jie yong-jie merged commit 24a4bd6 into develop Mar 5, 2021
@yong-jie yong-jie deleted the refactor/locales/static branch March 5, 2021 07:36
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.

2 participants