function _l10n_update_locale_import_one_string in Localization update 6
Same name and namespace in other branches
- 7 l10n_update.locale.inc \_l10n_update_locale_import_one_string()
Imports a string into the database
Parameters
$op: Operation to perform: 'db-store', 'db-report', 'mem-store' or 'mem-report'
$value: Details of the string stored
$mode: Should existing translations be replaced LOCALE_IMPORT_KEEP, LOCALE_IMPORT_OVERWRITE or LOCALE_UPDATE_OVERRIDE_DEFAULT
$lang: Language to store the string in
$file: Object representation of file being imported, only required when op is 'db-store'
$group: Text group to import PO file into (eg. 'default' for interface translations)
2 calls to _l10n_update_locale_import_one_string()
- _l10n_update_locale_import_po in ./
l10n_update.locale.inc - Parses Gettext Portable Object file information and inserts into database
- _l10n_update_locale_import_read_po in ./
l10n_update.locale.inc - Parses Gettext Portable Object file into an array
File
- ./
l10n_update.locale.inc, line 243 - Override part of locale.inc library so we can manage string status
Code
function _l10n_update_locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL, $group = 'default') {
static $report = array(
'additions' => 0,
'updates' => 0,
'deletes' => 0,
'skips' => 0,
);
static $headerdone = FALSE;
static $strings = array();
switch ($op) {
// Return stored strings
case 'mem-report':
return $strings;
// Store string in memory (only supports single strings)
case 'mem-store':
$strings[$value['msgid']] = $value['msgstr'];
return;
// Called at end of import to inform the user
case 'db-report':
return array(
$headerdone,
$report['additions'],
$report['updates'],
$report['deletes'],
$report['skips'],
);
// Store the string we got in the database.
case 'db-store':
// We got header information.
if ($value['msgid'] == '') {
$header = _locale_import_parse_header($value['msgstr']);
// Get the plural formula and update in database.
if (isset($header["Plural-Forms"]) && ($p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->filename))) {
list($nplurals, $plural) = $p;
db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", $nplurals, $plural, $lang);
}
else {
db_query("UPDATE {languages} SET plurals = %d, formula = '%s' WHERE language = '%s'", 0, '', $lang);
}
$headerdone = TRUE;
}
else {
// Some real string to import.
$comments = _locale_import_shorten_comments(empty($value['#']) ? array() : $value['#']);
if (strpos($value['msgid'], "\0")) {
// This string has plural versions.
$english = explode("\0", $value['msgid'], 2);
$entries = array_keys($value['msgstr']);
for ($i = 3; $i <= count($entries); $i++) {
$english[] = $english[1];
}
$translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries);
$english = array_map('_locale_import_append_plural', $english, $entries);
foreach ($translation as $key => $trans) {
if ($key == 0) {
$plid = 0;
}
$plid = _l10n_update_locale_import_one_string_db($report, $lang, $english[$key], $trans, $group, $comments, $mode, L10N_UPDATE_STRING_DEFAULT, $plid, $key);
}
}
else {
// A simple string to import.
$english = $value['msgid'];
$translation = $value['msgstr'];
_l10n_update_locale_import_one_string_db($report, $lang, $english, $translation, $group, $comments, $mode);
}
}
}
// end of db-store operation
}