function locale_translate_file_attach_properties

Generates file properties from filename and options.

An attempt is made to determine the translation language, project name and project version from the file name. Supported file name patterns are: {project}-{version}.{langcode}.po, {prefix}.{langcode}.po or {langcode}.po. Alternatively the translation language can be set using the $options.

Parameters

object $file: A file object of the gettext file to be imported.

array $options: An array with options:

  • 'langcode': The language code. Overrides the file language.

Return value

object Modified file object.

2 calls to locale_translate_file_attach_properties()
locale_translate_get_interface_translation_files in drupal/core/modules/locale/locale.bulk.inc
Get interface translation files present in the translations directory.
locale_translate_import_form_submit in drupal/core/modules/locale/locale.bulk.inc
Form submission handler for locale_translate_import_form().

File

drupal/core/modules/locale/locale.bulk.inc, line 687
Mass import-export and batch import functionality for Gettext .po files.

Code

function locale_translate_file_attach_properties($file, $options = array()) {

  // Extract project, verion and language code from the file name. Supported:
  // {project}-{version}.{langcode}.po, {prefix}.{langcode}.po or {langcode}.po
  preg_match('!
    (                       # project OR project and version OR emtpy (group 1)
      ([a-z_]+)             # project name (group 2)
      \\.                    # .
      |                     # OR
      ([a-z_]+)             # project name (group 3)
      \\-                    # -
      ([0-9a-z\\.\\-\\+]+)     # version (group 4)
      \\.                    # .
      |                     # OR
    )                       # (empty)
    ([^\\./]+)               # language code (group 5)
    \\.                      # .
    po                      # po extension
    $!x', $file->filename, $matches);
  if (isset($matches[5])) {
    $file->project = $matches[2] . $matches[3];
    $file->version = $matches[4];
    $file->langcode = isset($options['langcode']) ? $options['langcode'] : $matches[5];
  }
  else {
    $file->langcode = Language::LANGCODE_NOT_SPECIFIED;
  }
  return $file;
}