Main menu

Custom export paths for Zip archives

For generating Zip archives, Loco defines a default path for each exportable file format. For example, an iOS project might be exported with paths like this:

en.lproj/Localizable.strings
fr.lproj/Localizable.strings

You can customize the format of these paths by passing the path parameter to the Export API's archive endpoint. This parameter takes the form of a string template. For the examples above the following template would work:

{%locale}.lproj/Localizable.strings

The endpoint takes this parameter in the query string, so make sure it's properly escaped. Here's the full URL:

https://localise.biz/api/export/archive/strings.zip?path=%7B%25locale%7D.lproj%2FLocalizable.strings

Platform aliases

The token {%locale} will be expanded into the default language tag for each project locale. If you've set a custom language tag it will be used, but you can specify any named alias with the following syntax:

{%locale|alias:ios}.lproj/Localizable.strings

Note the use of the pipe ("|") to specify the "alias" filter, then the colon (":") to provide the argument "ios". This is the name of the alias to use, and you can call it whatever you like. See platform aliases.

Template syntax

The following tokens can be used in export path templates:

  • lang
    {%lang} expands to just the language subtag of the locale, e.g. {%lang}.xml would expand to "en.xml" for the locale "en-GB".

  • script, region, variant and extension
    As with the language token, these expand just to the given subtag. e.g. {%lang}_{%region}.po would expand to "en_GB.po" for the locale "en-GB-x-ignore".

  • iso_639_2 and iso_639_3
    These expand to the ISO language code in the given standard. e.g. {%iso_639_2}-{%region}.xml would expand to "ger-DE.xml" for the locale "de-DE".

  • ext
    {%ext} expands to the default file extension of the current format. e.g. Localizable.{%ext} would expand to "Localizable.strings" when exporting to iOS strings.

  • namespace
    {%namespace} expands to the project slug or the namespace query string parameter if passed. e.g. for exporting to WordPress you might use: lang/{%namespace}-{%locale|alias:gettext}.po

Skipping empty values

You may notice that a template like {%lang}_{%region} poses a problem if there is no region. The solution is to put the separator between the opening brace and the percent symbol, like so:

locales/{%lang}{_%region}.po

This will suppress the "_" character if the %region token expands to an empty string.

Filters

The template syntax supports a filter to be applied to tokens following a pipe ("|") symbol. We've already covered the "alias" filter above. The following filters are also supported:

  • upper and lower
    These do what you probably expect. e.g. {%lang|upper}-{%region|lower} would expand to "EN-gb" for the locale "en-GB".

  • unless
    This filter suppresses a token if the expanded value is not the given argument. e.g. values{-%locale|unless:en} would expand to "values-de" for German, but simply "values" for English. Note that the value passed to the filter will be compared exactly with the expanded token.

You can chain filters together as long as the order makes sense. For example: values{-%locale|unless:en|alias:android}.