function _locale_import_parse_plural_forms in Drupal 4
Same name and namespace in other branches
- 5 includes/locale.inc \_locale_import_parse_plural_forms()
- 6 includes/locale.inc \_locale_import_parse_plural_forms()
- 7 includes/locale.inc \_locale_import_parse_plural_forms()
Parses a Plural-Forms entry from a Gettext Portable Object file header
@author Jacobo Tarrio
Parameters
$pluralforms A string containing the Plural-Forms entry:
$filename A string containing the filename:
Return value
An array containing the number of plurals and a formula in PHP for computing the plural form
1 call to _locale_import_parse_plural_forms()
- _locale_import_one_string in includes/
locale.inc - Imports a string into the database
File
- includes/
locale.inc, line 775 - Admin-related functions for locale.module.
Code
function _locale_import_parse_plural_forms($pluralforms, $filename) {
// First, delete all whitespace
$pluralforms = strtr($pluralforms, array(
" " => "",
"\t" => "",
));
// Select the parts that define nplurals and plural
$nplurals = strstr($pluralforms, "nplurals=");
if (strpos($nplurals, ";")) {
$nplurals = substr($nplurals, 9, strpos($nplurals, ";") - 9);
}
else {
return FALSE;
}
$plural = strstr($pluralforms, "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 {
drupal_set_message(t('The translation file %filename contains an error: the plural formula could not be parsed.', array(
'%filename' => theme('placeholder', $filename),
)), 'error');
return FALSE;
}
}