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

Add built-in translations to components #4961

Closed
5 tasks done
jcfranco opened this issue Jul 18, 2022 · 4 comments
Closed
5 tasks done

Add built-in translations to components #4961

jcfranco opened this issue Jul 18, 2022 · 4 comments
Assignees
Labels
4 - verified Issues that have been released and confirmed resolved. epic Large scale issues to be broken up into sub-issues and tracked via sprints and/or project. i18n-l10n issues dealing with internationalization/localization

Comments

@jcfranco
Copy link
Member

jcfranco commented Jul 18, 2022

Overview

Currently, our components have placed the responsibility of text translations on the user. Unfortunately, this pattern has lead to some unnecessary boilerplate from teams/projects that have to support more than one locale and do not provide customized strings (e.g., each project needs to set up translation for the same strings and update each component).
The goal for this epic is to make it easier for developers to bring in components w/o having to worry about setting up translations themselves.

Tasks

  • Define pattern for localized components (see notes below) (feat: add built-in translations #5065)

  • Add script to generate types for t9n bundles for type safety (feat: add built-in translations #5065)

  • Plan automation of translation-bundles

    • make sure to follow supported locales
    • use t9n naming
    • need to consider that designs may need to be updated to accommodate translations (aim to get translations early for this)
    • keep CLDR data-driven strings (e.g., dates, raw number data) outside of bundles
    • special considerations may be needed for RTL
    • error strings will need to be localized
      action items
    • Franco + Anvesh will work on a PR with the translation bundle scaffolding in place
    • Once ☝️ is ready, the next steps is to review and test our setup

Notes

  • No implementation details should be exposed, this will give us total flexibility on translation/loading implementation, we can revisit if we need to adopt a different lib for consistency across components – first iteration can be a simple JSON file fetcher
  • String bundles should:
    • be placed under src/components/<component>/assets/t9n/
    • have a main bundle (manually updated), and the rest will be automatically generated and named per their locale
      • the structure for the above could be anything as long as it does not unnecessarily add bytes, is easy to maintain and is clear to distinguish the main file from the rest
    • be JSON files – need to determine structure (a flat object of strings may be the best way to support string overrides, if needed
  • To support backwards-compatibility:
    • intl<Prop> values should no longer be set by default
    • after loading the built-in bundle, any provided intl<Prop>s should be merged w/ the built-in strings
    • technically, this would break anyone referencing the strings, but we expect this to not be a common use case
  • requests/bundles must be cached to handle multiple components of the same type loading later or in parallel
  • All core t9n behavior should be placed in a module and reused across components

Questions

  • Do we need to support runtime locale changes before 1.0.0?
    • one idea would be to only support at the HTML level and set up a mutation observer
  • Do we need to support changes at a global level (e.g., change strings for all buttons vs per instance) before 1.0.0?
  • Where to derive locale from (e.g., navigator.language, document.documentOwner.lang, global util)?
  • How often to update locale bundles?

Additional Resources

Prototype: #4960

i18n libs

cc @benelan @geospatialem

@jcfranco jcfranco added the epic Large scale issues to be broken up into sub-issues and tracked via sprints and/or project. label Jul 18, 2022
@geospatialem geospatialem added the 0 - new New issues that need assignment. label Jul 19, 2022
@annierm18 annierm18 added the i18n-l10n issues dealing with internationalization/localization label Jul 19, 2022
@anveshmekala
Copy link
Contributor

Following is the list of high-risk locales provided by @annierm18 from localization team which can be used to test before shipping PR #5471

  • Western languages – German, Spanish, French
  • Norwegian
  • Asian languages – Japanese, Chinese (Simplified or Traditional)
  • RTL/bi-di languages – Arabic, Hebrew
  • Cyrillic and non-Latin languages – Russian, Ukrainian, Greek
  • Other – Thai, Turkish, any specific customer language

@annierm18
Copy link
Contributor

I have completed testing for the test cases listed in the screen shot below. Tickets were opened for all issues found (links are included in screenshot).

Screenshot (109)

cc: @anveshmekala

anveshmekala added a commit that referenced this issue Dec 14, 2022
**Related Issue:** #4961 

## Summary

This PR will add built-in translations to the components across calcite
.

Notable features  :

- Users no longer need to parse translated strings, translations are now
built-in. List of the supported locale's can be found
[here](https://developers.arcgis.com/calcite-design-system/localization/#locale-support).
- One can overwrite default translations for a given locale using
`messageOverrides` property.
- Specifying `lang` at document level , component level and ancestor
level is supported.
- component level always takes precedence and then ancestor's followed
by doc level.
      ```
<!--Though arabic is specified as lang at doc level , button component
will follow Spanish for string localization . -->
       <html lang="ar"> 
       <body>
       <calcite-button lang="es"> </calcite-button>
       </body>
       </html>
       ```

### Migration 

To migrate calcite components that use `intl` props & properties for
accessible labels for overriding default values, refer to the following
example to start using `messageOverrides` object property.

Before:
```
<!-- overriding via intl props -->
<calcite-color-picker intl-saturation="{custom value}"  intl-save="{custom value}"> </calcite-color-picker>
```
Current :
```
<!-- leveraging building translations. 
 display translations for Spanish lang -->
<calcite-color-picker lang="es"> </calcite-color-picker>

<!-- if the user wants to customize the default translations provided, one can override as below -->
<calcite-color-picker lang="es"> </calcite-color-picker>
<script>
const colorpickEl = document.querySelector('calcite-color-picker')
colorpickerEl.messageOverrides = { blue = "custom value" , red = "custom value" }
</script>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: JC Franco <jfranco@esri.com>
Co-authored-by: Ben Elan <benelan@users.noreply.github.com>
Co-authored-by: jona7150 <jturpin@esri.com>
Co-authored-by: Ben Elan <belan@esri.com>
Co-authored-by: Calcite Admin <calcite-admin@esri.com>
Co-authored-by: jcfranco <jcfranco@users.noreply.github.com>
Co-authored-by: Kitty Hurley <khurley@esri.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Eliza Khachatryan <eli97736@esri.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Driscoll <mdriscoll@esri.com>
Co-authored-by: Alison Stump <alisonailea@users.noreply.github.com>
@anveshmekala anveshmekala added 3 - installed Issues that have been merged to master branch and are ready for final confirmation. and removed 0 - new New issues that need assignment. labels Dec 15, 2022
@github-actions
Copy link
Contributor

Installed and assigned for verification.

@geospatialem geospatialem added 4 - verified Issues that have been released and confirmed resolved. and removed 3 - installed Issues that have been merged to master branch and are ready for final confirmation. labels Jan 18, 2023
@geospatialem
Copy link
Member

Verified on master. Note the path to the string bundles is src/components/<component>/assets/<component>/t9n/, where the full path differs from the proposal above, but is acceptable.

Of the above issues mentioned by Aine above, 2 have been closed and are included in the 1.0 release, and the remaining lower priority issues have been allocated to the February milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - verified Issues that have been released and confirmed resolved. epic Large scale issues to be broken up into sub-issues and tracked via sprints and/or project. i18n-l10n issues dealing with internationalization/localization
Projects
None yet
Development

No branches or pull requests

4 participants