PHP

The PHP ecosystem does not have a single standard internationalization system. While Gettext PO is common, a simpler approach involves using PHP snippets and definitions to create key-value pairs. LingoHub supports these PHP resource files for streamlined localization.

Format

  • Each define statement must end with a semicolon ;.
  • The define keyword is case-insensitive (e.g., define or DEFINE).
  • Keys and values can be enclosed in single or double quotes.
  • Supported placeholders include standard printf formatters such as %s, %d, and %3.4d.
  • Comments beginning with # are parsed and assigned as descriptions to the subsequent segment.
  • Newlines can be escaped using \n.
  • LingoHub supports single-line define statements; multi-line statements are not supported.
  • Content before the first define line and after the last define line is preserved and exported exactly as imported.

Example

Additional example files are available on GitHub.

<?php
  # File header comment.

  # Comment for the logoff segment.
  define('logoff', 'Log off');
  define("double_quotes", "'single' and \"double\" quotes");
  define("single_quotes", '\'single\' and "double" quotes');
  define('placeholder', 'Hello %s!');
  define('multi_line', "A multi-line \n string.");
?>

References