File Extensions |
.php |
API Extension |
php_array |
Import |
Yes |
Export |
Yes |
Plural forms support |
No |
Description support |
No |
An array is an ordered list or collection of items. The items of the array can be basically any type in PHP: a number, a string, an object, another array, etc. We often use strings as values in our locale message arrays. PHP arrays come in two major kinds:
-
Indexed — these arrays are ordered implicitly, e.g. ['red', 'green', 'blue']
-
Associative — these arrays contain pairs of keys (which can be integers or strings), and associated values, e.g. ['first_name' => 'Adam', 'last_name' => 'McMan', 'age' => 22]
The value of an array element can be set during initialization or using the variable name of the array itself.
<?php // during initialization $my_array = ['foo' => 'bar']; // using variable name $my_second_array['key'] = 'value'
This method of setting values can be mixed and matched.
Working with Arrays
When pulling from the command line, message files will be sent in the following format using an associative, named array.
<?php $lang['key'] = 'translated message'; $lang['another_key'] = 'Another translated message';
Ensure app is set up to work with this kind of format. Don’t return an anonymous array in message files and use the name $lang
for the messages array.
Code Sample
<?php $lang['boolean_key'] = '--- true '; $lang['empty_string_translation'] = ''; $lang['key_with_description'] = 'Check it out! This key has a description! (At least in some formats)'; $lang['key_with_line-break'] = 'This translations contains a line-break.'; $lang['nested.deeply.key'] = 'Wow, this key is nested even deeper.'; $lang['nested.key'] = 'This key is nested inside a namespace.'; $lang['null_translation'] = ''; $lang['sample_collection'] = '--- - first item - second item - third item '; $lang['simple_key'] = 'Just a simple key with a simple message.'; $lang['unverified_key'] = 'This translation is not yet verified and waits for it. (In some formats we also export this status)';