This proposal is about splitting source catalogs. Compiled message catalogs always contain all messages in project for now.
Deprecate localeDir, srcPathDirs and srcPathIgnorePatterns. These will be replaced with catalogs, described below.
Deprecate add-locale command and replace it with locales configuration.
Allow override default rootDir. All relative paths inside catalogs configuration will be relative to rootDir.
Key is a path to catalog or catalogs. It’s either absolute or relative path to rootDir.
{locale} placeholder is replaced with catalog’s locale.
Value specify a source from which messages are extracted. It can be also an array of sources. The most common one is a directory, which is traversed recursively and messages are collected from source files.
If the path starts with run! then messages are loaded from executable script. See loading messages from scripts below.
Catalog names are always without extension because that depends on serializer, e.g. json and po.
Messages can also be loaded dynamically from a script. If the source path starts with run! (e.g. run!scripts/fetch_graphql_enums.js), the script is executed and returned messages are added to catalog.
defaults: "New Hope"
defaults: "Empire Strikes Back"
defaults: "Return of the Jedi"
If returned value is an object with name attribute then value of this attribute is used in {name} placeholder.
Until now, babel plugin extracted messages into _build directory. Files from this directory were merged into single catalog which was used to create locale files.
_build directory will be removed right after messages are extracted and collected messages (without translations) will be stored in message file (POT or JSON extension). This file is language agnostic and contains only message definitions.
In next step, message file is used to create locale specific catalog by merging translation from previous locale files.
This allows to check if message source have changed, access message definitions in other tools and optionally, create/edit message files manually (if automatic extracting isn’t possible).
User should be warned if messages are collected, but there’s no corresponding locale directory for them (e.g. the root locale directory is missing).
When a new locale directory is created in subdirectory, all translations from parent locale should be moved here.
The other way around, when directory is removed, there should be a way how to merge tranlations to parent directory.
locale directory contains messages from componentA and componentB.
Here, locale contains messages from componentA and componentB, but not from largeComponentC, because these messages are collected in largeComponentC/locale.
Directories must be created manually. In monorepos this might be extra work, but for example in Lerna it’s just lerna exec -- mkdir locales.
It’s not possible to rename catalogs.
It’s not possible to collect messages from multiple independent sources into single locale directory.
This seems to be very repetitive. On the other hand it allows overriding Lingui config per directory.