For Developers‎ > ‎Design Documents‎ > ‎

UI Localization (aka Translations)

If you find an error in an existing translation, please file a bug using the translation template.
You can also help provide translations for the chromium-browser package on Ubuntu.

How to add a string
  1. Add the string to the grd file (generated_resources.grd, webkit_strings.grd, chromium_strings.grd or google_chrome_strings.grd).  See below in the "Overview of files" section for guidence on which file to add the string to.
  2. Surround the string with an appropriate <if> clause to ensure that it's only included it on platforms where it's actually used (e.g. Mac and Linux). Strings used on all platforms can omit the <if> clause.
  3. The next time you build the solution, this will automatically add the en-US string to en-US.dll.
  4. In your code, include ui/base/l10n/l10n_util.h and grit/generated_resources.h.
  5. To get the string, use l10n_util::GetStringUTF16.  Alternately, you can use l10n_util::GetStringFUTF16 which will replace placeholders $1 through $4 with the extra arguments of GetStringFUTF16.  Note that we generally prefer to use UTF-16 encoded strings for user-visible text.
How to add an Android/Java string
  1. Add the string to the grd file in the Java folder (e.g. content/public/android/java/strings/android_content_strings.grd).  Strings should be named in all caps with the prefix IDS_.  For example: IDS_MY_STRING.
  2. At build time, an Android-style strings.xml file will be generated in the out directory.
  3. You can reference these strings in Java code using the standard R.string.my_string syntax, or in Android layouts using @string/my_string.  Note: the name is lowercase and the IDS_ prefix is stripped.
If you are contributing code to the Google Chrome version of Chromium, then this is all you need to do.  The process of translating the string from en-US to the other languages will be handled by Google's translation team.

If you are adding a string to Chromium that you want for a different version of Chromium and you want to have translation in other languages, you need to add translations to the .xtb files in /src/chrome/app/resources.  These files have a translation id that is based on a hash of the en-US string (see /src/tools/grit/grit/extern/ for details on the hash).

Overview of files

  Strings for the main UI language (en-US) get added to these files.  If the string is used in webkit (i.e., shows up in content), then add the string to webkit_strings.grd.  Otherwise, add the string to generated_resources.grd.  These grd files are the "pivot" format on which everything else is based.

  These files contain translations in each language of the en-US strings in the grd files.

  GRIT (Google Resource and Internationalization Tool) is a script that that runs during the build that combines the grd files with the xtb files to generate a C++ header file with string IDs and a Windows resource file (.rc) containing the strings.

  Similar to the generated_resources.grd and webkit_strings.grd but these files allow for having strings that refer to Google Chrome vs Chromium.  These files should define strings for the same IDs, they just have different translations.  Visual Studio will build the correct file based on an environment variable.

  This file contains values that vary by locale, but are not sent to translators (i.e., they are used by developers).  For example, the default font size depends on locale, so we put it in this file.  We put the en-US value in locale_settings.grd and for all other locales, we put values in the locale_settings*.xtb files.  You must provide a value for all locales for the grd file to build properly.

   Tool that tries to find unused strings. This tool does not currently take <if> statements into consideration.

Workflow for how strings get translated for Google Chrome
  1. String gets added to a grd file
  2. Translators are provided with the new grd files
  3. Translations are created and new xtb files are generated
  4. The new xtb files are checked into the Chromium source tree

    Strings are included on all platforms by default and will needlessly increase the download size if not used.  It's important to judiciously surround strings with an appropriate <if> clauses  to ensure that they are only included on the platforms where they're actually used.
Subpages (1): Mac Notes