locales.rst (12381B)
1 .. _localization: 2 3 ================ 4 Localized Builds 5 ================ 6 7 Localization repacks 8 ==================== 9 10 To save on build time, the build system and automation collaborate to allow 11 downloading a packaged en-US Firefox, performing some locale-specific 12 post-processing, and re-packaging a locale-specific Firefox. Such artifacts 13 are termed "single-locale language repacks". There is another concept of a 14 "multi-locale language build", which is more like a regular build and less 15 like a re-packaging post-processing step. 16 17 .. note:: 18 19 These builds rely on make targets that don't work for 20 `artifact builds <https://bugzilla.mozilla.org/show_bug.cgi?id=1387485>`_. 21 22 Instructions for single-locale repacks for developers 23 ----------------------------------------------------- 24 25 This assumes that ``$AB_CD`` is the locale you want to repack with; you 26 find the available localizations from `firefox-l10n <https://github.com/mozilla-l10n/firefox-l10n>`_. 27 28 #. You must have a built and packaged object directory, or a pre-built 29 ``en-US`` package. 30 31 .. code-block:: shell 32 33 ./mach build 34 ./mach package 35 36 #. Repackage using the locale-specific changes. 37 38 .. code-block:: shell 39 40 ./mach build installers-$AB_CD 41 42 You should find a re-packaged build at ``OBJDIR/dist/``, and a runnable binary 43 in ``OBJDIR/dist/l10n-stage/``. The ``installers`` target runs quite a few 44 things for you, including getting the localizations from 45 https://github.com/mozilla-l10n/firefox-l10n (or updating it if already 46 present). It will clone them into ``~/.mozbuild/l10n-central``. If you prefer to 47 have the l10n repositories at a different location on your disk, you can point 48 to the directory via 49 50 .. code-block:: shell 51 52 ac_add_options --with-l10n-base=/make/this/a/absolute/path 53 54 This build also packages a language pack. 55 56 Instructions for language packs 57 ------------------------------- 58 59 Language packs are extensions that contain just the localized resources. Building 60 them doesn't require an actual build, but they're only compatible with the 61 ``mozilla-central`` source they're built with. 62 63 64 .. code-block:: shell 65 66 ./mach build langpack-$AB_CD 67 68 This target shares much of the logic of the ``installers-$AB_CD`` target above, 69 and does the check-out of the localization repository etc. It doesn't require 70 a package or a build, though. The generated language pack is in 71 ``OBJDIR/dist/$(MOZ_PKG_PLATFORM)/xpi/``. 72 73 .. note:: 74 75 Despite the platform-dependent location in the build directory, language packs 76 are platform independent, and the content that goes into them needs to be 77 built in a platform-independent way. 78 79 Instructions for multi-locale builds 80 ------------------------------------ 81 82 If you want to create a single build with multiple locales, you will do 83 84 #. Create a build and package 85 86 .. code-block:: shell 87 88 ./mach build 89 ./mach package 90 91 #. Create the multi-locale package: 92 93 .. code-block:: shell 94 95 ./mach package-multi-locale --locales de it zh-TW 96 97 On Android, this produces a multi-locale GeckoView AAR and multi-locale APKs, 98 including GeckoViewExample. You can test different locales by changing your 99 Android OS locale and restarting GeckoViewExample. You'll need to install with 100 the ``MOZ_CHROME_MULTILOCALE`` variable set, like: 101 102 .. code-block:: shell 103 104 env MOZ_CHROME_MULTILOCALE=en-US,de,it,zh-TW ./mach android install-geckoview_example 105 106 Multi-locale builds without compiling 107 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 108 109 For deep technical reasons, artifact builds do not support multi-locale builds. 110 However, with a little work, we can achieve the same effect: 111 112 #. Arrange a ``mozconfig`` without a compilation environment but with support 113 for the ``RecursiveMake`` build backend, like: 114 115 .. code-block:: shell 116 117 ac_add_options --disable-compile-environment 118 export BUILD_BACKENDS=FasterMake,RecursiveMake 119 ... other options ... 120 121 #. Configure. 122 123 .. code-block:: shell 124 125 ./mach configure 126 127 #. Manually provide compiled artifacts. 128 129 .. code-block:: shell 130 131 ./mach artifact install [-v] 132 133 #. Build. 134 135 .. code-block:: shell 136 137 ./mach build 138 139 #. Produce a multi-locale package. 140 141 .. code-block:: shell 142 143 ./mach package-multi-locale --locales de it zh-TW 144 145 This build configuration is fragile and not generally useful for active 146 development (for that, use a full/compiled build), but it certainly speeds 147 testing multi-locale packaging. 148 149 General flow of repacks 150 ----------------------- 151 152 The general flow of the locale repacks is controlled by 153 ``$MOZ_BUILD_APP/locales/Makefile.in`` and ``toolkit/locales/l10n.mk``, plus 154 the packaging build system. The three main entry points above all trigger 155 related build flows: 156 157 #. Get the localization repository, if needed 158 #. Run l10n-merge with a prior clobber of the merge dir 159 #. Copy l10n files to ``dist``, with minor differences here between ``l10n-%`` and ``chrome-%`` 160 #. Repackage and package 161 162 Details on l10n-merge are described in its own section below. 163 The copying of files is mainly controlled by ``jar.mn``, in the few source 164 directories that include localizable files. ``l10n-%`` is used for repacks, 165 ``chrome-%`` for multi-locale packages. The repackaging is dedicated 166 Python code in ``toolkit/mozapps/installer/l10n-repack.py``, using an existing 167 package. It strips existing ``chrome`` l10n resources, and adds localizations 168 and metadata. 169 170 Language packs don't require repackaging. The windows installers are generated 171 by merely packaging an existing repackaged zip into to an installer. 172 173 Exposing strings 174 ================ 175 176 The localization flow handles a few file formats in well-known locations in the 177 source tree. 178 179 Alongside being built by including the directory in ``$MOZ_BUILD_APP/locales/Makefile.in`` 180 and respective entries in a ``jar.mn``, we also have configuration files tailored 181 to localization tools and infrastructure. They're also controlling which 182 files l10n-merge handles, and how. 183 184 These configurations are TOML files. They're part of the bigger 185 localization ecosystem at Mozilla, and `the documentation about the 186 file format <http://moz-l10n-config.readthedocs.io/en/latest/fileformat.html>`_ 187 explains how to set them up, and what the entries mean. In short, you find 188 189 .. code-block:: toml 190 191 [paths] 192 reference = browser/locales/en-US/** 193 l10n = {l}browser/** 194 195 to add a directory for all localizations. Changes to these files are best 196 submitted for review by :Pike or :flod. 197 198 These configuration files are the future, and right now, we still have 199 support for the previous way to configuring l10n, which is described below. 200 201 The locations are commonly in directories like 202 203 :file:`browser/`\ ``locales/en-US/``\ :file:`subdir/file.ext` 204 205 The first thing to note is that only files beneath :file:`locales/en-US` are 206 exposed to localizers. The second thing to note is that only a few directories 207 are exposed. Which directories are exposed is defined in files called 208 ``l10n.ini``, which are at a 209 `few places <https://searchfox.org/mozilla-central/search?q=path%3Al10n.ini&redirect=true>`_ 210 in the source code. 211 212 An example looks like this 213 214 .. code-block:: ini 215 216 [general] 217 depth = ../.. 218 219 [compare] 220 dirs = browser 221 browser/branding/official 222 223 [includes] 224 toolkit = toolkit/locales/l10n.ini 225 226 This tells the l10n infrastructure three things: 227 228 * resolve the paths against the directory two levels up 229 * include files in :file:`browser/locales/en-US` and 230 :file:`browser/branding/official/locales/en-US` 231 * load more data from :file:`toolkit/locales/l10n.ini` 232 233 For projects like Thunderbird and SeaMonkey in ``comm-central``, additional 234 data needs to be provided when including an ``l10n.ini`` from a different 235 repository: 236 237 .. code-block:: ini 238 239 [include_toolkit] 240 type = hg 241 mozilla = mozilla-central 242 repo = https://hg.mozilla.org/ 243 l10n.ini = toolkit/locales/l10n.ini 244 245 This tells the l10n infrastructure where to find the repository, and where inside 246 that repository the ``l10n.ini`` file is. This is needed because for local 247 builds, :file:`mail/locales/l10n.ini` references 248 :file:`mozilla/toolkit/locales/l10n.ini`, which is where the comm-central 249 build setup expects toolkit to be. 250 251 Now that the directories exposed to l10n are known, we can talk about the 252 supported file formats. 253 254 File formats 255 ------------ 256 257 The following file formats are known to the l10n tool chains: 258 259 Fluent 260 Used in Firefox UI, both declarative and programmatically. 261 Properties 262 Used from JavaScript and C++. When used from js, also comes with 263 plural support (avoid if possible). 264 ini 265 Used by the crashreporter and updater, avoid if possible. 266 267 Adding new formats involves changing various different tools, and is strongly 268 discouraged. 269 270 Exceptions 271 ---------- 272 Generally, anything that exists in ``en-US`` needs a one-to-one mapping in 273 all localizations. There are a few cases where that's not wanted, notably 274 around locale configuration and locale-dependent metadata. 275 276 For optional strings and files, l10n-merge won't add ``en-US`` content if 277 the localization doesn't have that content. 278 279 For the TOML files, the 280 `[[filters]] documentation <https://moz-l10n-config.readthedocs.io/en/latest/fileformat.html#filters>`_ 281 is a good reference. In short, filters match the localized source code, optionally 282 a ``key``, and an action. An example like 283 284 .. code-block:: toml 285 286 [filters] 287 path = "{l}calendar/chrome/calendar/calendar-event-dialog.properties" 288 key = "re:.*Nounclass[1-9].*" 289 action = "ignore" 290 291 indicates that the matching messages in ``calendar-event-dialog.properties`` are optional. 292 293 For the legacy ini configuration files, there's a Python module 294 ``filter.py`` next to the main ``l10n.ini``, implementing :py:func:`test`, with the following 295 signature 296 297 .. code-block:: python 298 299 def test(mod, path, entity = None): 300 if does_not_matter: 301 return "ignore" 302 if show_but_do_not_merge: 303 return "report" 304 # default behavior, localizer or build need to do something 305 return "error" 306 307 For any missing file, this function is called with ``mod`` being 308 the *module*, and ``path`` being the relative path inside 309 :file:`locales/en-US`. The module is the top-level dir as referenced in 310 :file:`l10n.ini`. 311 312 For missing strings, the :py:data:`entity` parameter is the key of the string 313 in the en-US file. 314 315 l10n-merge 316 ========== 317 318 The chrome registry in Gecko doesn't support fallback from a localization to ``en-US`` at runtime. 319 Thus, the build needs to ensure that the localization as it's built into 320 the package has all required strings, and that the strings don't contain 321 errors. To ensure that, we're *merging* the localization and ``en-US`` 322 at build time, nick-named l10n-merge. 323 324 For Fluent, we're also removing erroneous messages. For many errors in Fluent, 325 that's cosmetic, but when a localization has different values or attributes 326 on a message, that's actually important so that the DOM bindings of Fluent 327 can apply the translation without having to load the ``en-US`` source to 328 compare against. 329 330 The process can be manually triggered via 331 332 .. code-block:: bash 333 334 $> ./mach build merge-$AB_CD 335 336 It creates another directory in the object dir, :file:`browser/locales/merge-dir/$AB_CD`, in 337 which the sanitized files are stored. The actual repackaging process only looks 338 in the merged directory, so the preparation steps of l10n-merge need to ensure 339 that all files are generated or copied. 340 341 l10n-merge modifies a file if it supports the particular file type, and there 342 are missing strings which are not filtered out, or if an existing string 343 shows an error. See the Checks section below for details. If the files are 344 not modified, l10n-merge copies them over to the respective location in the 345 merge dir. 346 347 Checks 348 ------ 349 350 As part of the build and other localization tool chains, we run a variety 351 of source-based checks. Think of them as linters. 352 353 The suite of checks is usually determined by file type, i.e., there's a 354 suite of checks for Fluent files and one for properties files, etc. 355 356 Localizations 357 ------------- 358 359 Now that we talked in-depth about how to expose content to localizers, 360 where are the localizations? 361 362 We host all locales in a git monorepo. All of our 363 localizations can be found on https://github.com/mozilla-l10n/firefox-l10n. 364 365 You can search inside our localized files on 366 `Transvision <https://transvision.mozfr.org/>`_.