Skip to main content
PHP Arrays (.php)
Nick Ustinov avatar
Written by Nick Ustinov
Updated this week

PHP Arrays are a common method for managing localization strings in PHP applications. These files store translations as key-value pairs within an array, making it easy to access and use localized strings within your code. Lokalise supports PHP Array files, allowing for efficient translation management directly within your projects.

Technical information

Overview

Format name:
PHP Arrays

File extensions:
.php

Common use cases:
Managing and organizing localization strings in PHP applications.

Technical details:

  • Structure: PHP Array files consist of key-value pairs stored within a PHP array. Each key represents a specific translation string, and the corresponding value is the translated text. The variable name for the array can be customized.

  • Encoding: UTF-8

Example:
Here's an example of a typical PHP Array file used for localization:

<?php
$lang["username"] = "Username";
$lang["password"] = "Enter password";
$lang["app"] = "Lokalise";

By default, the variable name is $lang, but you can provide any other name, for example $_["username"]. During the export, a variable with the same name will be used as well.

Using with Lokalise

Lokalise supports PHP Array files, allowing you to manage and translate your localization strings efficiently.

Supported project types

Please note that PHP Array files can be uploaded only to Web and mobile projects.

Known limitations

  • Custom variable names: While custom variable names are supported, this feature has certain limitations:

    • The custom variable name is set only if you're importing a file with new keys (meaning this name is not updatable).

    • The custom variable name cannot be modified using the Lokalise editor.

    • You cannot have different custom variables in a single file.

  • Multiple assignment: Multiple assignment written in the following way is not supported: $lang["key1"] = $lang["key2"] = "Translation";.

Did this answer your question?