Conversation
Co-authored-by: Barret Schloerke <[email protected]>
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 |
schloerke
left a comment
There was a problem hiding this comment.
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
Co-authored-by: Barret Schloerke <[email protected]>
Co-authored-by: Barret Schloerke <[email protected]>
|
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. |
schloerke
left a comment
There was a problem hiding this comment.
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 |
schloerke
left a comment
There was a problem hiding this comment.
LGTM given small JS change
Co-authored-by: Barret Schloerke <[email protected]>
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
languageoption is outlined in the updatedmultilangvignette. 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 entirelanguagelist item fromlearnr::tutorial(), which is processed into a resources list as expected byi18nextintutorial_i18n_process_language_options()and written into the.jsfile containing the initialization code bytutorial_i18n_prepare_language_file(). Finallytutorial_i18n_lang()returns thehtmlDependency()for thei18nextinitialization 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.jsonfile), 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
multilangvignette 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.