function _locale_import_one_string in Drupal 5
Same name and namespace in other branches
- 4 includes/locale.inc \_locale_import_one_string()
- 6 includes/locale.inc \_locale_import_one_string()
- 7 includes/locale.inc \_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 ('overwrite' or 'keep')
$lang: Language to store the string in
$file: Object representation of file being imported, only required when op is 'db-store'
3 calls to _locale_import_one_string()
- st in includes/
install.inc - Hardcoded function for doing the equivalent of theme('placeholder') when the theme system is not available.
- _locale_import_po in includes/
locale.inc - Parses Gettext Portable Object file information and inserts into database
- _locale_import_read_po in includes/
locale.inc - Parses Gettext Portable Object file into an array
File
- includes/
locale.inc, line 709 - Admin-related functions for locale.module.
Code
function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL) {
static $additions = 0;
static $updates = 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,
$additions,
$updates,
);
// Store the string we got in the database
case 'db-store':
// We got header information
if ($value['msgid'] == '') {
$hdr = _locale_import_parse_header($value['msgstr']);
// Get the plural formula
if ($hdr["Plural-Forms"] && ($p = _locale_import_parse_plural_forms($hdr["Plural-Forms"], $file->filename))) {
list($nplurals, $plural) = $p;
db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", $nplurals, $plural, $lang);
}
else {
db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", 0, '', $lang);
}
$headerdone = TRUE;
}
else {
$comments = _locale_import_shorten_comments($value['#']);
// Handle a translation for some plural string
if (strpos($value['msgid'], "\0")) {
$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;
}
$loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key]));
if (!empty($loc->lid)) {
// a string exists
$lid = $loc->lid;
// update location field
db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $comments, $lid);
$trans2 = db_fetch_object(db_query("SELECT lid, translation, plid, plural FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang));
if (!$trans2->lid) {
// no translation in current language
db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key);
$additions++;
}
else {
if ($mode == 'overwrite' || $trans2->translation == '') {
db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE locale = '%s' AND lid = %d", $trans, $plid, $key, $lang, $lid);
if ($trans2->translation == '') {
$additions++;
}
else {
$updates++;
}
}
}
}
else {
// no string
db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english[$key]);
$loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key]));
$lid = $loc->lid;
db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, $trans, $plid, $key);
if ($trans != '') {
$additions++;
}
}
$plid = $lid;
}
}
else {
$english = $value['msgid'];
$translation = $value['msgstr'];
$loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english));
if (!empty($loc->lid)) {
// a string exists
$lid = $loc->lid;
// update location field
db_query("UPDATE {locales_source} SET location = '%s' WHERE source = '%s'", $comments, $english);
$trans = db_fetch_object(db_query("SELECT lid, translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang));
if (!$trans->lid) {
// no translation in current language
db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation);
$additions++;
}
else {
if ($mode == 'overwrite') {
//overwrite in any case
db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid);
if ($trans->translation == '') {
$additions++;
}
else {
$updates++;
}
}
else {
if ($trans->translation == '') {
db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid);
$additions++;
}
}
}
}
else {
// no string
db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english);
$loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english));
$lid = $loc->lid;
db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, $translation);
if ($translation != '') {
$additions++;
}
}
}
}
}
// end of db-store operation
}