Main menu

JSON language pack formats supported by the importer

JSON is a generic file format that can have any structure. This makes importing difficult, so Loco recognizes the following structures as translation mappings:

Flat

A flat structure will be imported as simple key/value pairs, for example:

{ 
    "hello" : "Hello World", 
}

This will import a single asset with ID "hello" and source text "Hello World"

Nested

Loco supports key folding for nested structures. For example:

{
    "pleasantry": { 
        "hello" : "Hello World", 
        "goodbye" : "So long!" 
    }
}

This will import two assets with dot-separated IDs "pleasantry.hello" and "pleasantry.goodbye". There is no limit to the depth of this structure.

Plurals

Loco supports plural definitions as either JSON Arrays, or JSON objects with keys zero, one, two, few, many, other:

{
    "foo" : [ "1 foo", "%u foos" ],
    "bar" : { "one" : "1 bar", "other" : "%u bars" }
}

This will import two singular assets with IDs "foo" and "bar" linked to their respective plural forms "foo-plural" and "bar-plural". Read more about how Loco handles plurals.

Multiple locales

JSON files containing multiple locales can be imported, as long as there is a top-level key that looks like your locale code. For example:

{
  "fr": {
    "greeting": {
      "hello": "Bonjour tout le Monde"
    }
  }
}

This will import a single asset with ID "greeting.hello". The same key folding rules as above are applied, but the top-level locale keys will be discarded.

Note that only one language can be imported at the same time from a file like this. From the Loco dashboard importer, select the language you want to extract. Via the API, specify it with the locale parameter, e.g. ?locale=fr

Be aware that if you specify a locale that does not exactly match a top-level key, Loco will treat the structure as if it were a single locale. That means that if you told Loco that the above example was in Spanish (locale=es) it would not see "fr" as a locale code, and would import an asset called "fr.greeting.hello".

Lookup keys

Your JSON file may by mapped by Asset IDs or by full source text.

By default Loco assumes object keys are Asset IDs, so if you want to map keys to your source locale you must tell Loco what to do. For example:

{
    "Hello World" : "Bonjour",
}

This will import an English translation and a French translation, but only if you tell Loco that the keys are English and the values are French. See General notes on importing for how to specify the locales.

Chrome extensions

Loco supports the format used in messages.json files for Chrome extensions.

See Chrome extension docs