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 i18n and add additional translation keys #479

Merged
merged 28 commits into from
Feb 2, 2021

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Jan 26, 2021

I've refactored the internationalization scripts to remove the jquery-i18next dependency in favor of a hand-rolled function that achieves similar results, but lets us store some of the i18n parameters in data-i18n- HTML element attributes.

I also plan to refactor the i18n_translations() function to use a better format and preparation process that will be more robust for Unicode characters not in UTF-8.

The big change here is that localization will now:

  • Use the key in the data-i18n attribute of the HTML element to look up the translation
  • OR use the key in the data-i18n-attr-<name> attribute to look up the translation for the <name> attribute.
    • e.g. data-i18n-attr-title = "button.runcodetitle" uses the button.runcodetitle key to set the title attribute of the current element.
    • These elements must have a data-i18n attribute for internationalization to occur, if the innerHTML is not to be set, then set data-i18n = "".
  • Additional options to be passed to the i18next.t() method can be stored in the data-i18n-opts attribute. This is particularly useful for passing {count: collection.length} for pluralization.

I added an R function helper i18n_span() to help set the above attributes from the R side. For buttons created in JavaScript, these attributes are added as/where needed.

PR task list:

  • Update NEWS
  • Add tests (if possible)
  • Update documentation with devtools::document()

Fixes #476

@gadenbuie gadenbuie marked this pull request as ready for review January 28, 2021 16:50
@gadenbuie gadenbuie marked this pull request as draft January 28, 2021 17:18
@gadenbuie gadenbuie marked this pull request as ready for review January 28, 2021 18:20
Copy link
Collaborator

@schloerke schloerke left a comment

Choose a reason for hiding this comment

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

LGTM given small code shuffle / notes

data-raw/i18n_translations.yml Outdated Show resolved Hide resolved
inst/lib/tutorial/tutorial.js Outdated Show resolved Hide resolved
inst/lib/tutorial/tutorial.js Outdated Show resolved Hide resolved
inst/lib/i18n/tutorial-i18n-init.js Show resolved Hide resolved
inst/lib/i18n/tutorial-i18n-init.js Outdated Show resolved Hide resolved
inst/lib/i18n/tutorial-i18n-init.js Show resolved Hide resolved
@gadenbuie
Copy link
Member Author

LGTM given small code shuffle / notes

Thanks @schloerke! I've updated the comments and shuffled the code as requested 😄

@gadenbuie gadenbuie linked an issue Feb 2, 2021 that may be closed by this pull request
@gadenbuie gadenbuie changed the title Refactor i18n and add more translation keys Refactor i18n and add additional translation keys Feb 2, 2021
@gadenbuie gadenbuie merged commit 7ab246f into rstudio:master Feb 2, 2021
@gadenbuie gadenbuie deleted the i18n-more-tokens branch February 2, 2021 17:13
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.

Additional items for internationalization
2 participants