1 gettext.inc | _locale_import_parse_plural_forms($plural_forms, $filepath) |
Parses a Plural-Forms entry from a Gettext Portable Object file header.
Parameters
string $plural_forms: A string containing the Plural-Forms entry.
string $filepath: A string containing the filepath.
Return value
An array containing the number of plurals and a formula in PHP for: computing the plural form.
Related topics
File
- core/
includes/ gettext.inc, line 612 - Gettext parsing and generating API.
Code
function _locale_import_parse_plural_forms($plural_forms, $filepath) {
// First, delete all whitespace.
$plural_forms = strtr($plural_forms, array(" " => "", "\t" => ""));
// Select the parts that define nplurals and plural.
$nplurals = strstr($plural_forms, "nplurals=");
if (strpos($nplurals, ";")) {
$nplurals = substr($nplurals, 9, strpos($nplurals, ";") - 9);
}
else {
return FALSE;
}
$plural = strstr($plural_forms, "plural=");
if (strpos($plural, ";")) {
$plural = substr($plural, 7, strpos($plural, ";") - 7);
}
else {
return FALSE;
}
// Get PHP version of the plural formula.
$plural = _locale_import_parse_arithmetic($plural);
if ($plural !== FALSE) {
return array($nplurals, $plural);
}
else {
backdrop_set_message(t('The translation file %filepath contains an error: the plural formula could not be parsed.', array('%filepath' => $filepath)), 'error');
return FALSE;
}
}