Skip to page
LocaleasySecurity

Config

localeasy.json tells the CLI which files are source files, where their translations go, and which project they belong to. The CLI uses the nearest one in the directory it runs in or above it.

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

The fields of localeasy.json
FieldTypeWhat it is
$schemastringWhere an editor finds the JSON Schema. The CLI ignores it.
version2Required. The config format; always 2.
projectstringThe id of the project these files push to and pull from, a UUID. init --create and init --project write it.
serverstringThe server's address. Without it the CLI uses https://localeasy.app. LOCALEASY_URL and --api-url win over it.
sourceLocalestringThe language the source files are written in, as a BCP 47 tag.
localesstring[]The translation languages to push, pull and report. Without it, every language the project has.
formatstringThe file format. Without it the CLI detects it from each file's name and content.
dialectstringHow the messages spell placeholders and plurals. Without it, the format's default.
defaultsobjectIn a monorepo root: settings every workspace inherits. A workspace's own value wins.
filesobject[]The file groups: which files are source files and where their translations go.
extractobjectWhere localeasy extract finds the keys the code uses. A package's own; defaults can't hold it.
typesstringWhere localeasy types writes the declarations of the source files' keys, such as src/messages.d.ts, relative to this file. A package's own.
workspacesstring[]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.

The fields of a file group
FieldTypeWhat it is
sourcestringRequired. The source files, as a path pattern relative to this localeasy.json.
translationstringRequired. The translation files, as a path pattern. It needs one of {locale}, {locale_snake}, {locale_android} or {language}.
namespacestringThe namespace these files hold. It may use {namespace} and {package}. Without it: {namespace} from the path, or default when the source pattern has none.
formatstringThe format of this group's files.
dialectstringThe 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.

The fields of extract
FieldTypeWhat it is
extractorstringRequired. i18next: i18next-cli, which the project installs (npm i -D i18next-cli). The CLI does not bundle it.
inputstring[]Required. The code to scan, as globs relative to this localeasy.json, such as src/**/*.{ts,tsx}.
optionsobjectPassed 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") to checkout. A key the code names no namespace for goes to i18next's translation, or to the first group's namespace when every group names a fixed one. options.defaultNS overrides 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 pull writes 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_one and files_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 a Date | number, and any other a string | 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.

Placeholders in file patterns
PlaceholderFor pt-BRWhat it is
{locale}pt-BRThe language as a BCP 47 tag.
{locale_snake}pt_BRThe tag with underscores.
{locale_android}pt-rBRThe tag as Android resource directories write it.
{language}ptThe language without its region.
{region}BRThe region alone.
{namespace}checkoutA namespace: letters, digits, ., _ and -. One source file per namespace.
{package}webThe 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.

File formats
formatFilesExtensionsDefault dialect
i18nexti18next JSON.jsoni18next
jsonJSON.jsonicu
json-flatFlat JSON.jsonicu
csvCSV.csvicu
propertiesJava .properties.propertiesicu
stringsApple .strings.stringsapple
pogettext PO.po, .potplain
androidAndroid strings.xml.xmlandroid
xliffXLIFF.xlf, .xliffxliff
yamlYAML.yaml, .ymlruby
arbFlutter ARB.arbarb
stringsdictApple .stringsdict.stringsdictapple
resx.NET RESX.resx, .reswdotnet
phpLaravel PHP.phplaravel
markdownMarkdown.md, .markdownplain

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 with other among them, such as one and other, is one plural key in any dialect; one whose other is empty is untranslated.
  • Apple: a .strings and a .stringsdict of the same table are two namespaces, so give one group a namespace of its own, as init prints it: {namespace}-stringsdict. A .stringsdict key whose format is one variable, such as %#@files@, is a plural key; any other format is a text key, with a plural key name::substitution.variable for each variable.
  • RESX: a <data> with a type or mimetype, such as an image, is skipped, so pull writes a language's file without it. init takes the neutral Strings.resx beside Strings.sv.resx as the source, in English unless --source-locale says 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 the laravel dialect :name, :Name and :NAME are one argument; a colon after a letter or digit, as in 10:30, is text. Pipe plurals, such as {0} None|[1,*] :count, stay one text, as Laravel writes them. init finds lang/{locale}/{namespace}.php.
  • Markdown: each paragraph, heading, list item, quote, table cell, and the front matter's title and description, is a text. Its key is the headings above it and its place under the last one, such as setup/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 until push --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. .mdx is 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, format and dialect from the root's defaults. 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 files of 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.json is the namespace web-common, and apps/admin/locales/en/common.json is admin-common. Without the prefixes both would be common, which is an error.
  • localeasy init writes the group of one layout: the one with the most languages. It lists the others it found, with the group to add for each.
  • pull writes 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 overwrite counts only for the branch it went to. push --translations compares 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.