PHP — Translate Toolkit 1.13.0 documentation

# PHP

Many PHP programs make use of a localisable string array. The toolkit supports the full localisation of such files with php2po and po2php.

## Conformance

Our format support allows:

- Single and double quoted strings (both for keys and values)

      <?php
      $variable = 'string';
      $messages["language"] = 'Language';
      define('item', "another string");

- PHP simple variable syntax

      <?php
      $variable = 'string';
      $another_variable = "another string";

- PHP square bracket array syntax

      <?php
      $messages['language'] = 'Language';
      $messages['file'] = "File";
      $messages["window"] = 'Window';
      $messages["firewall"] = "Firewall";

- PHP array syntax

  New in version 1.7.0.

      <?php
      // Can be 'array', 'Array' or 'ARRAY'.
      $lang = array(
         'name' => 'value',
         'name2' => "value2",
         "key1" => 'value3',
         "key2" => "value4",
      );

- PHP define syntax

  New in version 1.10.0.

      <?php
      define('item', 'string');
      define('another_item', "another string");
      define("key", 'and another string');
      define("another_key", "yet another string");

- Escape sequences (both for single and double quoted strings)

      <?php
      $variable = 'He said: "I\'ll be back"';
      $another_variable = "First line \n second line";
      $key = "\tIndented string";

- Multiline entries

      <?php
      $lang = array(
         'name' => 'value',
         'info' => 'Some hosts disable automated mail sending
                on their servers. In this case the following features
                cannot be implemented.',
         'name2' => 'value2',
      );

- Various layouts of the id

      <?php
      $string['name'] = 'string';
      $string[name] = 'string';
      $string[ 'name' ] = 'string';

- Comments

  Changed in version 1.10.0.

      <?php
      # Hash one-line comment
      $messages['language'] = 'Language';

      // Double slash one-line comment
      $messages['file'] = 'File';

      /*
         Multi-line
         comment
      */
      $messages['help'] = 'Help';

- Whitespace before end delimiter

  New in version 1.10.0.

      <?php
      $variable = 'string'     ;

      $string['name'] = 'string'     ;

      $lang = array(
         'name' => 'value'           ,
      );

      define('item', 'string'    );

- Nested arrays with any number of nesting levels

  New in version 1.11.0.

      <?php
      $lang = array(
         'name' => 'value',
         'datetime' => array(
            'TODAY' => 'Today',
            'YESTERDAY' => 'Yesterday',
            'AGO' => array(
                0 => 'less than a minute ago',
                2 => '%d minutes ago',
                60 => '1 hour ago',
            ),
            'Converted' => 'Converted',
            'LAST' => 'last',
         ),
      );

- Whitespace in the array declaration

  New in version 1.11.0.

      <?php
      $variable = array    (
         "one" => "this",
         "two" => "that",
      );

- Blank array declaration, then square bracket syntax to fill that array

  New in version 1.12.0.

      <?php
      global $messages;
      $messages = array();

      $messages['language'] = 'Language';
      $messages['file'] = 'File';

## Non-Conformance

The following are not yet supported:

- Keyless arrays:

      <?php
      $days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');

      $messages['days_short'] = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');

- Nested arrays without key for a nested array:

      <?php
      $lang = array(array("key" => "value"));

- Array entries without ending comma:

      <?php
      $variable = array(
         "one" => "this",
         "two" => "that"
      );

- String concatenation:

      <?php
      $messages['welcome'] = 'Welcome ' . $name . '!';
      $messages['greeting'] = 'Hi ' . $name;

- Assignment in the same line a multiline comment ends:

      <?php
      /*
         Multi-line
         comment
      */ $messages['help'] = 'Help';

- Heredoc

- Nowdoc