Skip to content

Internationalization (i18n)

Gary edited this page Oct 17, 2022 · 15 revisions

Overview

Internationalization (on this page) refers to code techniques to make the IDE's user-visible strings localizable into other languages. Other aspects of i18n such as date/time formats, currency symbols, sorting orders, icons and images containing "text", and auto-layout to handle different UI string lengths are not explicitly discussed here at this time.

General Concepts

  • User-visible strings must not be hardcoded in the source code; they must be stored in separate files (one set of such files per-language), and loaded at runtime from the appropriate language files based on users' desired UI language
  • Strings must not be composed in the code by string concatenation, even if those strings themselves are localizable; the order of a sentence or phrase is often quite different in various languages; use a numbered or named placeholder substitution technique appropriate to the source code languages / frameworks
  • Don't code runtime assumptions that UI text will have a certain hardcoded value (e.g. in "if" statements); either match against the localized string, or (better) have a different way to handle such things using non-visible attributes (CSS classes, element IDs, etc.)
  • Ideally, UI will automatically adapt to different UI text length and not be hardcoded to only fit the English text and/or localizers are provided a way to localize the actual layout (neither of these are currently implemented in much of the UI)
  • We are not localizing logging / diagnostics messages, our command-line utilities such as rstudio-server, or our documentation

String Localization Process

  • at this time we are maintaining English and French strings
  • at a suitable point in the product cycle (when all or most UI changes have been completed), use the "locdiff" tool to generate a report showing new and modified strings, as an aid in updating the French strings
  • see the README here: https://github.com/rstudio/rstudio/tree/main/src/gwt/tools/locdiff

GWT Code

  • For GWT, we use Java .properties files, generally at each level of the Java namespace, and Constants and Messages interfaces (the latter if string has placeholders)
  • Eventually each .properties file will have multiple instances, one per language with a language identifier in the filename, but there is only one Constants file for each set
  • Follow the many existing examples in the code; it's relatively straightforward
  • Example:
  • UIBinder files (*.ui.xml) also use .properties files for localized strings
  • We aren't currently providing localized versions of UI icons and images (we have several that contain text, so ideally these would eventually have per-language variants)
  • If you need leading whitespace in a localized string, one technique is to put a placeholder at the beginning and just pass in an empty string for that placeholder (.properties strings ignore leading whitespace), e.g. "{0} This has a leading space we want to keep."
  • GWT i18n overview
  • RStudio GWT i18n tools readme

Menus and Commands

  • The source file for Menus and Commands is Commands.cmd.xml
  • When you build GWT (e.g. ant), scripts will generate/update the English property and constants files (only if Commands.cmd.xml has been modified since those files were last generated)
  • Developers modifying Commands.cmd.xml are responsible for ensuring they have done a GWT build, and must commit the modified property and constants files along with Commands.cmd.xml; failure to do so will break the build (by design) with the build error:
 [echo] Commands.cmd.xml i18n checksum matches: false

UI strings in C++ Code

  • There are strings surfaced in the UI that come from the rserver and rsession executables; these are C++ projects and currently we haven't enabled string localization for them

Qt-Based Desktop (C++ specific)

  • We are not localizing any UI strings contained in the C++ desktop code for the legacy QtWebEngine-based desktop IDE

Electron UI Code

  • The Electron-based RStudio desktop uses the i18next package to handle localized strings. The localized strings are in JSON files found in the src/node/desktop/src/assets/locales folder (e.g. en.json, fr.json).

Visual Editor (panmirror)

Desktop Installer (Windows)

  • The RStudio installer for Windows is currently English-only

UI strings in R Code

  • NYI