Lokalise does not keep files (or file templates) as such. Instead, as you upload, we parse the files, extract keys and values and store these in the database. When you need to export, we generate files in any required format.

Once a key is parsed and stored in the database it may have a filename attribute


Platforms

Lokalise supports four platforms – iOS, Android, Web and Other. Assigning a key to one or more platforms actually means that this file will be exported to file formats associated with the platform, i.e. assigning a key to an iOS platform means it would be included with Apple Strings and Apple XLIFF file exports, but would not be exported with a JSON export (as it belongs to Web platform).

Each key can be attributed to a single filename per platform. You can set the attribution using the Key editor (click key name in the editor, then navigate to the Advanced tab).


Uploading and downloading different file structure patterns

There are several approaches how you may organize your keys into files and folders. Below we will try to cover all the possible options, but feel free to contact us in the web support chat if you need us to cover additional cases. There are multiple ways to exchange files with Lokalise, the most popular are Web UI, Lokalise CLI tool and GitHub/GitLab/Bitbucket integrations.

You can use %LANG_ISO%  placeholder in filenames in order to rotate the language code on export.

The following examples are based on the Lokalise CLI tool, which you would need to have installed.


Example 1. Single file per language.

As soon as you start using a translation management system there is no real need to break down your keys into hundreds of files – this just creates unnecessary overhead. We recommend keeping all your keys in a single file per language, whichever the the file format is.

locale/en.json
locale/ru.json

Uploading:

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file upload \
  --file "locale/en.json" \
  --lang-iso en

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file upload \
  --file "locale/ru.json" \
  --lang-iso ru

Downloading:

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file download \
  --format json \
  --bundle-structure "locale/%LANG_ISO%.json" \
  --original-filenames=false \
  --unzip-to .

We've used bundle-structure  parameter when exporting.


Example 2. Language code is part of the folder name

This pattern is used on Android and iOS. Quite similar to Example 1, the only difference is that %LANG_ISO% variable is being rotated in the folder name:

values/strings.xml
values-ru/strings.xml

Uploading:

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file upload \
  --file "values/strings.xml" \
  --lang-iso en


# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file upload \
  --file "values-ru/strings.xml" \
  --lang-iso ru

Downloading:

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file download \
  --format xml \
  --bundle-structure "values-%LANG_ISO%/strings.xml" \
  --original-filenames=false \
  --unzip-to .

Note, we are using values-%LANG_ISO%/strings.xml here, however in the case that it is a base language, the system will omit the -%LANG_ISO%  part as required by Android.


Example 3. Multiple files per language folder

en.lproj/Localizable.strings
en.lproj/Extra.strings
ru.lproj/Localizable.strings
ru.lproj/Extra.strings

Uploading:

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file upload \
  --file "en.lproj/\*.strings" \
  --lang-iso en


# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file upload \
  --file "ru.lproj/\*.strings" \
  --lang-iso ru

Note, we've escaped *  on Linux/Mac.

Downloading:

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file download \
  --format strings \
  --directory-prefix "%LANG_ISO%.lproj" \
  --original-filenames=true \
  --unzip-to .

We've added --directory-prefix  along with --original-filenames  parameters here.


Example 4. Multiple folders, language code part of the filename or folder.

moduleFirst/src/main/res/values-en/strings.xml
moduleFirst/src/main/res/values-ru/strings.xml
moduleSecond/src/main/res/values-en/strings.xml
moduleSecond/src/main/res/values-ru/strings.xml

Uploading:

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file upload \
  --file "ModuleFirst/src/main/res/values-en/strings.xml,\
          ModuleSecond/src/main/res/values-en/strings.xml" \
  --lang-iso en


# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file upload \
  --file "ModuleFirst/src/main/res/values-ru/strings.xml,\
          ModuleSecond/src/main/res/values-ru/strings.xml" \
  --lang-iso ru

Downloading:

# lokalise2 \
  --token <token> \
  --project-id <project_id> \
  file download \
  --format xml \
  --original-filenames=true \
  --directory-prefix ""
  --unzip-to .

Note, we are using empty --directory-prefix  parameter here to omit creation of language folders, as they are part of the filename.

Different language codes for different platforms

As Lokalise allows storing multiple platform files in the same project it's often important to have different language codes depending on the format you are exporting. You need to adjust this manually in Web UI and the Downloads page. Once adjusted, click "Build" to save the settings. Now, when using the CLI tool, the system will apply last saved setting for that particular file format.

Did this answer your question?