-
Notifications
You must be signed in to change notification settings - Fork 240
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
More internationalization #456
Conversation
Co-authored-by: Barret Schloerke <barret@rstudio.com>
Move documentation from tutorial_i18n_custom_language() into the vignette
This comment has been minimized.
This comment has been minimized.
Internationalization added an inner <span> to the button elements, so we need to check the parent button element in case the event is fired from the child <span>. The delegateTarget property is jQuery's currentTarget equivalent and has slightly better browser support.
language:
en:
button:
runcode: Run!
text:
areyousure: Are you certain?
es:
button:
runcode: Ejecutar
fr: fr-translation.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implement this change: #456 (comment)
Let's also convert to htmldependencies |
- Simplify structure of language arg - Remove need for template file - Use i18n_ prefix for all related functions - Update multilang vignette - Allow .json for all languages or just one - Update tests
- button.questionsubmit and button.questiontryagain - localizes after UI output changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a news entry
Co-authored-by: Barret Schloerke <barret@rstudio.com>
Co-authored-by: Barret Schloerke <barret@rstudio.com>
A final thought: we might consider updating the documentation build process to also pull in vignettes, similar to pkgdown, so that the multilang vignette can be hosted online as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM given exercise_plural
can be utilized
This comment has been minimized.
This comment has been minimized.
…t namespace For historical reasons, i18next falls back to a language _within_ a namespace, before falling back to a namespace within the same language. See i18next issue 1260
@schloerke Can you give the last change a quick look? I realized a subtle detail in the way i18next handles fallback languages and namespaces. For historical reasons, if a key is missing in a namespace, i18next falls back to the fallback language key in that namespace before it falls back to the same key in the original language's namespace. As an example:
I was setting the default namespaces as
which is not ideal. The fix I've added is to keep the same
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM given small JS change
Co-authored-by: Barret Schloerke <barret@rstudio.com>
This PR builds on #441 (and includes the history in that branch) to extend the internationalization features and to expose the configuration options to the user for customization at a per-tutorial basis.
The usage and new format of the
language
option is outlined in the updatedmultilang
vignette. There are quite a few different possibilities for the YAML options, ranging from simply changing the base language of the tutorialto overriding the display text for a specific language
or to override the display text for multiple languages
or to provide the customizations in a JSON file
Technical Changes
I've made a few changes compared with the approach in #441 that I'll outline briefly.
The first is that complete translations are now in R in
tutorial_i18n_translations()
. I think this will make it easier for R users to contribute more translations.tutorial_i18n_lang()
now receives the entirelanguage
list item fromlearnr::tutorial()
, which is processed into a resources list as expected byi18next
intutorial_i18n_process_language_options()
and written into the.js
file containing the initialization code bytutorial_i18n_prepare_language_file()
. Finallytutorial_i18n_lang()
returns thehtmlDependency()
for thei18next
initialization which contains the user's customizations.Previously, a small amount of work was done to not re-create the initialization dependency file. Because that file can now depend on another external file (the
custom-language.json
file), I didn't really see any performance benefit to avoiding re-writing the file, so we now just write it on every render.Users now have the
multilang
vignette and the documentation fromtutorial_i18n_custom_language()
to learn about language customization options. The latter is exported to facilitate creating the JSON file and to perform minimal validation of the custom language options.Because the translations have been moved into R functions, the function documentation and the vignette both update automatically, so new translations can be added by updating
tutorial_i18n_translations()
without needing to update documentation in multiple locations.