PHP Array

Last updated: September 09, 2024Author: Jakub Pomykała
php-array
File format value
php-array

PHP Arrays are simple objects which can contain simple key-value entries. PHP Arrays are simple objects which can contain simple key-value entries. The key is treated as a unique translation key, and value which is translated message. One PHP file array contains language translations for only on language. For example: messages_de_DE.php contains translated message for German (Germany) locale.

File format example

<?php
    return [
        "HELLO_WORLD" => "Hello world!",
        "MY_TRANSLATION_KEY" => "This is my translation message!"
    ];
?>

SimpleLocalize also recognizes nested PHP arrays, as shown below.

<?php
    return [
        "LEVEL_1" => [
            "HELLO_WORLD" => "First level - Hello world!",
            "LEVEL_2" => [
              "HELLO_WORLD" => "Second level - Hello world!",
            ]
        ],
        "MY_TRANSLATION_KEY" => "This is my translation message!"
    ];
?>

Above PHP file will result with:

  • LEVEL_1.HELLO_WORLD,
  • LEVEL_1.LEVEL_2.HELLO_WORLD,
  • MY_TRANSLATION_KEY translation keys in Translation Editor.

Upload translation files

Upload with command-line tool

simplelocalize upload --apiKey <PROJECT_KEY> \
  --uploadFormat php-array \
  --uploadPath ./messages_{lang}.php

Learn more about uploading translations with CLI.

Import with REST API

curl
    --request POST \
    --url 'https://api.simplelocalize.io/api/v2/import?uploadFormat=php-array&languageKey=en' \
    --header 'x-simplelocalize-token: <API_KEY>' \
    --form file=@/path/to/your/messages.php

Learn more about importing translations with API.

Download translation files

Download with command-line tool

simplelocalize download --apiKey <PROJECT_KEY> \
  --downloadFormat php-array \
  --downloadPath ./messages_{lang}.php

To download translations with nested keys use option WRITE_NESTED. See all download options.

simplelocalize download --apiKey <PROJECT_KEY> \
  --downloadFormat php-array \
  --downloadPath ./messages_{lang}.php \
  --downloadOptions WRITE_NESTED

Learn more about downloading translations with CLI.

Export with REST API

curl
    --request GET \
    --url https://api.simplelocalize.io/api/v3/export?downloadFormat=php-array \
    --header 'x-simplelocalize-token: <API_KEY>'

Learn more about exporting translations with API.

Was this helpful?