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.
object $file: A file object of the gettext file to be imported.
array $options: An array with options:
object Modified file object.
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;
}