Skip to main content
PHP Localization

Information about how Transifex handles the PHP (.php) file format.

Antonis Mylonas avatar
Written by Antonis Mylonas
Updated over 10 months ago

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"
);>


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[&#39;_MONDAY&#39;] = "Monday";
$LANG["_TUESDAY"] = &#39;Tuesday&#39;;

/**This is a multiline
* comment***/
$LANG["_WEDNESDAY"] = &#39;&#39;;

$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.

Did this answer your question?