Main menu

Supported PHP language packs

When you import a PHP file into Loco, it will check first if the file has a formal language pack structure. Generally this structure will be one or more arrays. Anything not matching such a structure will fall back to generic string extraction.

Supported language pack formats are as follows:


Symfony PHP language packs are a simple array format in a return statement:

return array (
   "hello" => "Hello World",

This would be imported as a single asset with ID hello and source text "Hello World".

See Symfony docs


Zend Framework's format is very similar to Symfony, except for the way it deals with plural forms.

return array (
  'apple' =>
  array (
    0 => '1 apple',
    1 => '%u apples',

This will import two Loco assets where "%u apples" is the plural form of "1 apple".

See Zend docs


CodeIgniter's array format uses a separate statement for each value because the language array is global across the entire framework. e.g.

$lang['example_hello'] = 'Hello World';
$lang['example_goodbye'] = 'So long!';

See CodeIgniter docs

Arbitrary code

The language pack parser is strict, because Loco doesn't actually execute the code. It just looks at it.

PHP comments are ignored, but dynamic code is not. If Loco encounters anything that isn't an array of constants it will not be treated as a language pack. For example, the following will not be parsed by Loco:

return array (
    $key => "value",
    'foo' => 'bar'."\n".'baz',
    'name' => $customName,
    'place' => getLocation(),

Any one of these entries would fail the language pack check, and Loco will treat the whole file as arbitrary code.

Extracting from any source code

If your PHP file is not identified as a language pack, the importer will fall back to a generic string extraction process based on xgettext. If you're working with Gettext (or WordPress) this may be your original intention.

The extraction process looks for translation function calls. For example the following would produce a single asset with the source translation "Hello World" because __ is a WordPress translation call:

echo __("Hello World","myApp");

The full list of functions Loco can identify is not listed here, but includes the translation functions used by Symfony, Drupal, WordPress and the PHP Gettext extension.