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

- PHP short array syntax

  New in version 2.3.0.

      <?php
      $variable = [
          "foo" => "bar",
          "bar" => "foo",
      ];

- Heredoc

  New in version 2.3.0.

      <?php
      $variable = <<<EOT
      bar
      EOT;

- Nowdoc

  New in version 2.3.0.

      <?php
      $variable = <<<'EOD'
      Example of string
      spanning multiple lines
      using nowdoc syntax.
      EOD;

- 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';

- Unnamed arrays:

  New in version 2.2.0.

      <?php
      return array(
         "one" => "this",
      );

- Array entries without ending comma:

  New in version 2.3.0.

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

- Array entries with space before comma:

  New in version 2.3.0.

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

- Nested arrays declared on the next line:

  New in version 2.3.0.

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

- Nested arrays with blank entries:

  New in version 2.3.0.

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

- Strings with slash asterisk on them:

  New in version 2.3.0.

      <?php
      $variable = array(
          'foo' => 'Other value /* continued',
       );

- Array entries with value on next line:

  New in version 2.3.0.

      <?php
      $variable = array(
          'foo' =>
              'bar',
       );

- Array defined in a single line:

  New in version 2.3.0.

      <?php
      $variable = array( 'item1' => 'value1', 'item2' => 'value2', 'item3' => 'value3' );

- Keyless arrays:

  New in version 2.3.0.

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

- Nested arrays without key for a nested array:

  New in version 2.3.0.

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

- Concatenation of strings and variables:

  New in version 2.3.0.

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

- Assignment in the same line a multiline comment ends:

  New in version 2.3.0.

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

- Keyless arrays assigned to another array:

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

- Laravel plurals are supported in the `LaravelPHPFile` class:

      <?php
      return [
          'apples' => 'There is one apple|There are many apples',
      ];

## Non-Conformance

The following are not yet supported:

- There are currently no known limitations.