PHP Arrays
File Extension(s) | .php |
i18n type(s) | PHP_ARRAY |
Sample data
<?php
$LANG = array(
"january" => "enero",
"february" => "febrero",
"march" => "marzo",
"april" => "abril",
"may" => "mayo",
"june" => "junio",
"july" => "julio",
"august" => "agosto",
"september" => "septiembre",
"october" => "octubre",
"november" => "noviembre",
"december" => "diciembre"
);>
Nested Arrays
The PHP Array parser currently supports flat, single-level arrays in which every value is a string. If your file contains nested arrays, the parser will only detect the innermost flat array, ignoring all other strings.
For example, the following structure will not be parsed correctly:
<?php
$lang = array(
'greeting' => 'Hello',
'navigation' => array(
'home' => 'Home',
'about' => 'About',
),
);
return $lang;
To ensure all strings are extracted, flatten the array into a single level using dot notation to preserve the key hierarchy:
<?php
$lang = array(
'greeting' => 'Hello',
'navigation.home' => 'Home',
'navigation.about' => 'About',
);
return $lang;
⚠️Warning: Flattening your array will require updates to any application code that references the nested keys.
Handling Variables in PHP Arrays
Our PHP parser is only responsible for detecting and extracting strings from a PHP Array. If variables are included, then they must be handled in the manner explained by the following example:
FOOTER_COPY1" => "© .date("Y") MY CORPORATION LTD. All Rights Reserved.
The function date needs to be replaced in the PHP file with variables as seen below:
<?php
$thisyear = date("Y");
return array(
"FOOTER_COPY1" => "© {$thisyear} MY CORPORATION LTD. All rights reserved."
);
PHP Alternative Array
File Extension(s) | .php |
i18n type(s) | PHP_ALT_ARRAY |
Sample data
<?php
$LANG['_MONDAY'] = "Monday";
$LANG["_TUESDAY"] = 'Tuesday';
/**This is a multiline
* comment***/
$LANG["_WEDNESDAY"] = '';
$LANG["_Thursday"] = "Thursday";
?>
PHP DEFINE statements
File Extension(s) | .php |
i18n type(s) | PHP_DEFINE |
Sample data
<?php
DEFINE("january", "enero");
DEFINE("february", "febrero");
DEFINE("march", "marzo");
DEFINE("april", "abril");
DEFINE("may", "mayo");
DEFINE("june", "junio");
DEFINE("july", "julio");
DEFINE("august", "agosto");
DEFINE("september", "septiembre");
DEFINE("october", "octubre");
DEFINE("november", "noviembre");
DEFINE("december", "diciembre");
?>
Default placeholders
These are the default placeholders that you could have in your file, and they will be recognized :
match: ['%1$s', '%(key1)s', '%s', '%d', '%.2f', '%-5d', '%+2d']
Download options
When you download a PHP file following any of the formats mentioned in this article for use in a particular language, all empty translations are replaced by translations in the source language.
When you download the file for translation, it only contains the translations in that language.
When you download the file for review, it only includes the reviewed translations.
Parser Behavior
The following table outlines what occurs to strings when using the API, CLI, or UI to manipulate translation files depending on download mode.
*The results are compatible with parser version 1.
💡Tip
Looking for more help? Get support from our Transifex Community Forum!
Find answers or post to get help from Transifex Support and our Community.

