rules
configuration is quite versatile to enable the correct directory structure in many use cases. Each rule uses glob
-like path patterns to collect a list of source files. You can specify multiple rules to combine different directory structures into your MotaWord translations.
Let's look at the default value for rules
:
{
"source-directory": "src/en",
"translations-directory": "src/{locale}",
"rules": {
"**/*": "{path}/{basename}"
}
}
This rule tells motaword
CLI:
take all the files in my
src/en
directory as source files and put their translations in the same path structure inside thesrc/{locale}
directory where{locale}
is each of your translation languages.
If your source and translations directories are organized in a simple manner, this can be sufficient for you. However, rules can handle very complex use cases. Let's take a look at one that is a little more complex than the default one:
You should look at the section Available variables in rules before the complex example, it will make the example easier to digest.
{
"source-directory": "src/main/resources/strings",
"translations-directory": "src/main/resources/translations",
"rules": {
"frontend/json/*.json": "{locale}/{path}/{basename}",
"frontend/**/*.yml": "{locale}/{path}/{filename}.yaml",
"pot/*.pot": "{locale}/{path}/{basename}",
"md/*.md": "markdown-translations/{locale}/{path}/{filename}.md"
},
"exclude-rules": [
"pot/passwords*"
]
}
A rules
configuration like this says a lot :)
To debug and understand what your rules say, you can always run motaword debug
. It will tell you how your rules are interpreted.
Let's go through the complex rules above:
Given we are translating our files into French, which has the language code
fr
- Take
src/main/resources/strings
as the base directory for my source files. - Take
src/main/resources/translations
as the base directory for translated files. The last folder is different than the source path. - Translate all of
.json
files insrc/main/resources/strings/frontend/json/
directory, without going down subdirectories- And put their (e.g. French) translations into
src/main/resources/translations/fr/frontend/json/
- And put their (e.g. French) translations into
- Translate all of
.yml
files undersrc/main/resources/strings/frontend/
directory, going recursively in all subdirectories- And put their (e.g. French) translations under
src/main/resources/translations/fr/
, by using respective relative path of the source file.
- And put their (e.g. French) translations under
- Translate all of
.md
files insrc/main/resources/strings/md/
directory, without going down subdirectories- And put their (e.g. French) translations into
src/main/resources/translations/fr/md/
- And put their (e.g. French) translations into
- And finally, while doing all of that, exclude all files in
src/main/resources/strings/pot
directory whose file name starts withpasswords
.
If you are still here, you are an expert motaword
configurer :)