An example
localeasy init writes this for a repository with locales/en/app.json and locales/sv/app.json:
{
"$schema": "https://localeasy.app/localeasy.schema.json",
"version": 2,
"project": "0192f5e4-7b1a-7c3d-8e9f-000000000001",
"sourceLocale": "en",
"locales": [
"sv"
],
"files": [
{
"source": "locales/en/{namespace}.json",
"translation": "locales/{locale}/{namespace}.json"
}
]
}A field the CLI does not know is an error, as is a language tag that is not written the canonical way (pt-BR, not pt_br). Both exit 78 and name the field.
$schema is the address of the config's JSON Schema on the server init ran against. An editor reads it to complete and check the fields. The CLI ignores it.
Fields
| Field | Type | What it is |
|---|---|---|
$schema | Type: string | What it is: Where an editor finds the JSON Schema. The CLI ignores it. |
version | Type: 2 | What it is: Required. The config format; always 2. |
project | Type: string | What it is: The id of the project these files push to and pull from, a UUID. init --create and init --project write it. |
server | Type: string | What it is: The server's address. Without it the CLI uses https://localeasy.app. LOCALEASY_URL and --api-url win over it. |
sourceLocale | Type: string | What it is: The language the source files are written in, as a BCP 47 tag. |
locales | Type: string[] | What it is: The translation languages to push, pull and report. Without it, every language the project has. |
format | Type: string | What it is: The file format. Without it the CLI detects it from each file's name and content. |
dialect | Type: string | What it is: How the messages spell placeholders and plurals. Without it, the format's default. |
defaults | Type: object | What it is: In a monorepo root: settings every workspace inherits. A workspace's own value wins. |
files | Type: object[] | What it is: The file groups: which files are source files and where their translations go. |
extract | Type: object | What it is: Where localeasy extract finds the keys the code uses. A package's own; defaults can't hold it. |
types | Type: string | What it is: Where localeasy types writes the declarations of the source files' keys, such as src/messages.d.ts, relative to this file. A package's own. |
workspaces | Type: string[] | What it is: In a monorepo root: directories, as globs, that each hold a localeasy.json of their own. |
A token is never part of the config. See Sign in.
File groups
Each entry of files is a group: the source files of one layout and the translation files that belong to them.
| Field | Type | What it is |
|---|---|---|
source | Type: string | What it is: Required. The source files, as a path pattern relative to this localeasy.json. |
translation | Type: string | What it is: Required. The translation files, as a path pattern. It needs one of {locale}, {locale_snake}, {locale_android} or {language}. |
namespace | Type: string | What it is: The namespace these files hold. It may use {namespace} and {package}. Without it: {namespace} from the path, or default when the source pattern has none. |
format | Type: string | What it is: The format of this group's files. |
dialect | Type: string | What it is: The dialect of this group's messages. |
A source file holds one namespace. Two files that come to the same namespace and language are an error (exit 78): give the groups distinct namespace values.
"files": [
{
"source": "android/app/src/main/res/values/strings.xml",
"translation": "android/app/src/main/res/values-{locale_android}/strings.xml",
"namespace": "android"
},
{
"source": "locales/en/{namespace}.json",
"translation": "locales/{locale}/{namespace}.json"
}
]pull writes a namespace through the first group whose namespace matches it. Put a group with a fixed namespace before one that takes any {namespace}.
Keys from the code
localeasy extract adds the keys the code uses to the source files, and localeasy types writes TypeScript declarations of the keys the source files have.
| Field | Type | What it is |
|---|---|---|
extractor | Type: string | What it is: Required. i18next: i18next-cli, which the project installs (npm i -D i18next-cli). The CLI does not bundle it. |
input | Type: string[] | What it is: Required. The code to scan, as globs relative to this localeasy.json, such as src/**/*.{ts,tsx}. |
options | Type: object | What it is: Passed to the extractor as they are, but for ignore, whose globs are relative to this localeasy.json, as input's are. For i18next, i18next-cli's extract options, such as functions, transComponents, keySeparator, ignore or defaultNS. |
"extract": {
"extractor": "i18next",
"input": ["src/**/*.{ts,tsx}"]
},
"types": "src/messages.d.ts"- A key goes to the source file of its namespace:
t("checkout:pay")tocheckout. A key the code names no namespace for goes to i18next'stranslation, or to the first group's namespace when every group names a fixed one.options.defaultNSoverrides both. - A namespace without a source file gets one where the group's
{namespace}pattern puts it. A key in a namespace no group can hold is skipped with a warning, and fails--check. - New keys go after the existing ones, which keep their text and order. The file is written in its format's own layout, JSON indented by two spaces, as
pullwrites translation files. A new key's text is the default the code gives, else empty. - A plural takes the forms of the source language. In the i18next format and formats without plurals, such as JSON, that is one key per form, such as
files_oneandfiles_other; in formats with plurals, such as PO or Android, one plural entry. - Keys the code was not seen to use are counted, never removed: a key built at run time can't be seen.
- In the declarations, an argument formatted as a number or plural is a
number, one formatted as a date or time aDate | number, and any other astring | number. Keys with a context and markup tags are left out.
Path placeholders
In source the language placeholders stand for sourceLocale. In translation they stand for each translation language.
| Placeholder | For pt-BR | What it is |
|---|---|---|
{locale} | For pt-BR: pt-BR | What it is: The language as a BCP 47 tag. |
{locale_snake} | For pt-BR: pt_BR | What it is: The tag with underscores. |
{locale_android} | For pt-BR: pt-rBR | What it is: The tag as Android resource directories write it. |
{language} | For pt-BR: pt | What it is: The language without its region. |
{region} | For pt-BR: BR | What it is: The region alone. |
{namespace} | For pt-BR: checkout | What it is: A namespace: letters, digits, ., _ and -. One source file per namespace. |
{package} | For pt-BR: web | What it is: The name of the directory the workspace's localeasy.json is in. |
Formats and dialects
The format is how the file is written. The dialect is how its messages spell placeholders and plurals. Set format when two formats share an extension and detection picks the wrong one. The first push to a namespace sets its dialect.
| format | Files | Extensions | Default dialect |
|---|---|---|---|
i18next | Files: i18next JSON | Extensions: .json | Default dialect: i18next |
json | Files: JSON | Extensions: .json | Default dialect: icu |
json-flat | Files: Flat JSON | Extensions: .json | Default dialect: icu |
csv | Files: CSV | Extensions: .csv | Default dialect: icu |
properties | Files: Java .properties | Extensions: .properties | Default dialect: icu |
strings | Files: Apple .strings | Extensions: .strings | Default dialect: apple |
po | Files: gettext PO | Extensions: .po, .pot | Default dialect: plain |
android | Files: Android strings.xml | Extensions: .xml | Default dialect: android |
xliff | Files: XLIFF | Extensions: .xlf, .xliff | Default dialect: xliff |
yaml | Files: YAML | Extensions: .yaml, .yml | Default dialect: ruby |
arb | Files: Flutter ARB | Extensions: .arb | Default dialect: arb |
stringsdict | Files: Apple .stringsdict | Extensions: .stringsdict | Default dialect: apple |
resx | Files: .NET RESX | Extensions: .resx, .resw | Default dialect: dotnet |
php | Files: Laravel PHP | Extensions: .php | Default dialect: laravel |
markdown | Files: Markdown | Extensions: .md, .markdown | Default dialect: plain |
dialect takes one of: mf2, plain, icu, arb, printf, python, python-brace, apple, dotnet, ruby, template, qt, i18next, laravel, android, xliff. A gettext entry takes its dialect from its own flags, such as c-format; an entry without one is plain text.
- YAML: a file whose only top-level key is its language, as Rails writes
en:, holds its keys under it, and each language's file is written under its own. A mapping of plural categories withotheramong them, such asoneandother, is one plural key in any dialect; one whoseotheris empty is untranslated. - Apple: a
.stringsand a.stringsdictof the same table are two namespaces, so give one group anamespaceof its own, asinitprints it:{namespace}-stringsdict. A.stringsdictkey whose format is one variable, such as%#@files@, is a plural key; any other format is a text key, with a plural keyname::substitution.variablefor each variable. - RESX: a
<data>with atypeormimetype, such as an image, is skipped, sopullwrites a language's file without it.inittakes the neutralStrings.resxbesideStrings.sv.resxas the source, in English unless--source-localesays otherwise. - Android: a
<string-array>with an item untranslated is left out of the language's file, so the app shows the source language's array, not a short one. - Laravel PHP: a file is
<?php return [ ... ];, with quoted keys, and quoted texts or nested arrays, read without running it. A variable in a double-quoted text, a function call, a constant,.and a heredoc are errors at their line. A comment above a key is its description. In thelaraveldialect:name,:Nameand:NAMEare one argument; a colon after a letter or digit, as in10:30, is text. Pipe plurals, such as{0} None|[1,*] :count, stay one text, as Laravel writes them.initfindslang/{locale}/{namespace}.php. - Markdown: each paragraph, heading, list item, quote, table cell, and the front matter's
titleanddescription, is a text. Its key is the headings above it and its place under the last one, such assetup/install/2, so a paragraph added to a section renames the texts after it in that section only. Code, HTML and the rest of the file stay as the source file has them. A text not yet translated is written in the source language, so the file stays whole. A paragraph deleted from the source stays in the documents untilpush --remove-missing. Translations come from Localeasy: a translated file's headings give it keys the source does not have, so translated documents you already have cannot be pushed or uploaded..mdxis not read.
Monorepos
A localeasy.json with workspaces is a root. Each directory the globs match that has a localeasy.json of its own is a workspace, with its own project and files.
{
"version": 2,
"defaults": {
"sourceLocale": "en",
"locales": ["sv", "de"]
},
"workspaces": ["packages/*"]
}{
"version": 2,
"project": "0192f5e4-7b1a-7c3d-8e9f-000000000001",
"files": [
{
"source": "locales/en/{namespace}.json",
"translation": "locales/{locale}/{namespace}.json"
}
]
}- A workspace inherits
server,sourceLocale,locales,formatanddialectfrom the root'sdefaults. Its own value wins. - Run at the root, a command works on every workspace.
--project <id>picks one. Run inside a workspace, it works on that one, still with the root's defaults. - A root with
filesof its own is a workspace too. - Paths in a workspace's config are relative to that workspace.
{package}is the workspace's directory name.
One project for the whole repository
Workspaces make one project per package, and a plan allows a number of projects (see Limits). To keep every package's texts in one project instead, use one localeasy.json at the root with a group for each package, and give each group a namespace of its own:
{
"version": 2,
"project": "0192f5e4-7b1a-7c3d-8e9f-000000000001",
"sourceLocale": "en",
"files": [
{
"source": "apps/web/locales/en/{namespace}.json",
"translation": "apps/web/locales/{locale}/{namespace}.json",
"namespace": "web-{namespace}"
},
{
"source": "apps/admin/locales/en/{namespace}.json",
"translation": "apps/admin/locales/{locale}/{namespace}.json",
"namespace": "admin-{namespace}"
},
{
"source": "packages/ui/src/i18n/en.json",
"translation": "packages/ui/src/i18n/{locale}.json",
"namespace": "ui"
}
]
}apps/web/locales/en/common.jsonis the namespaceweb-common, andapps/admin/locales/en/common.jsonisadmin-common. Without the prefixes both would becommon, which is an error.localeasy initwrites the group of one layout: the one with the most languages. It lists the others it found, with the group to add for each.pullwrites a namespace's translations by the group whose source file holds it, so each package's files stay in its own directory.
The lockfile and .localeasy/
localeasy.lock sits beside the root localeasy.json. For each file as it was last pushed or pulled, it holds a content hash and where the file went: the server, the project, and the branch unless it was main. A file that has not changed since makes no request there. For another server or project, the entry counts for nothing. Commit it.
{
"version": 2,
"files": {
"locales/en/app.json": {
"hash": "59f4d8b4b3089263fc9fb03bad52624c",
"server": "https://localeasy.app",
"project": "0192f5e4-7b1a-7c3d-8e9f-000000000001"
},
"locales/sv/app.json": {
"hash": "bcc69aaf272fa9b3e4a1ce044bfd0ae1",
"server": "https://localeasy.app",
"project": "0192f5e4-7b1a-7c3d-8e9f-000000000001",
"branch": "feature/checkout"
}
}
}- A source file pushed to a branch is not recorded: main's entry stays, so a push to main sends the file.
- A translation file imported with
--strategy overwritecounts only for the branch it went to.push --translationscompares with the pulled copy, whichever branch it came from. - A lockfile of version 1 holds the hash alone. It is still read: its source files are compared with the server, its translation files count as before, and an entry takes the new form when its file is next recorded.
.localeasy/base/ holds each translation file as pull last wrote it. push --translations compares your file with that copy to find what you changed. Add .localeasy/ to .gitignore.
A lockfile that cannot be read exits 78. Delete it and run localeasy pull --force to rebuild it. Without --force, a pull with no lockfile keeps every translation file that differs from the server's and has no pulled copy in .localeasy/base/, as in a fresh checkout. --force also replaces translation edits that were never pushed.