function _l10n_update_locale_import_one_string_db in Localization update 6
Same name and namespace in other branches
- 7.2 l10n_update.translation.inc \_l10n_update_locale_import_one_string_db()
- 7 l10n_update.locale.inc \_l10n_update_locale_import_one_string_db()
Import one string into the database.
Parameters
$report: Report array summarizing the number of changes done in the form: array(inserts, updates, deletes).
$langcode: Language code to import string into.
$source: Source string.
$translation: Translation to language specified in $langcode.
$textgroup: Name of textgroup to store translation in.
$location: Location value to save with source string.
$mode: Should existing translations be replaced LOCALE_IMPORT_KEEP, LOCALE_IMPORT_OVERWRITE or LOCALE_UPDATE_OVERRIDE_DEFAULT
$status: Status of translation if created: L10N_UPDATE_STRING_DEFAULT or L10N_UPDATE_STRING_CUSTOM
$plid: Optional plural ID to use.
$plural: Optional plural value to use.
Return value
The string ID of the existing string modified or the new string added.
2 calls to _l10n_update_locale_import_one_string_db()
- l10n_update_client_save_string in ./
l10n_update.module - Menu callback. Saves a string translation coming as POST data.
- _l10n_update_locale_import_one_string in ./
l10n_update.locale.inc - Imports a string into the database
File
- ./
l10n_update.locale.inc, line 338 - Override part of locale.inc library so we can manage string status
Code
function _l10n_update_locale_import_one_string_db(&$report, $langcode, $source, $translation, $textgroup, $location, $mode, $status = L10N_UPDATE_STRING_DEFAULT, $plid = NULL, $plural = NULL) {
$lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = '%s'", $source, $textgroup));
if (!empty($translation)) {
// Skip this string unless it passes a check for dangerous code.
// Text groups other than default still can contain HTML tags
// (i.e. translatable blocks).
if ($textgroup == "default" && !locale_string_is_safe($translation)) {
$report['skips']++;
$lid = 0;
}
elseif ($lid) {
// We have this source string saved already.
db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $location, $lid);
// Check existing translation and status of the string
$exists = db_fetch_object(db_query("SELECT lid, l10n_status FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $langcode));
if (!$exists) {
// No translation in this language.
db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $langcode, $translation, $plid, $plural);
$report['additions']++;
}
elseif ($exists->l10n_status == L10N_UPDATE_STRING_DEFAULT && $mode == LOCALE_UPDATE_OVERRIDE_DEFAULT || $mode == LOCALE_IMPORT_OVERWRITE) {
// Translation exists, only overwrite if instructed.
db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d, l10n_status = '%d' WHERE language = '%s' AND lid = %d", $translation, $plid, $plural, $status, $langcode, $lid);
$report['updates']++;
}
}
else {
// No such source string in the database yet.
db_query("INSERT INTO {locales_source} (location, source, textgroup) VALUES ('%s', '%s', '%s')", $location, $source, $textgroup);
$lid = db_result(db_query("SELECT lid FROM {locales_source} WHERE source = '%s' AND textgroup = '%s'", $source, $textgroup));
db_query("INSERT INTO {locales_target} (lid, language, translation, plid, plural, l10n_status) VALUES (%d, '%s', '%s', %d, %d, %d)", $lid, $langcode, $translation, $plid, $plural, $status);
$report['additions']++;
}
}
elseif ($mode == LOCALE_IMPORT_OVERWRITE) {
// Empty translation, remove existing if instructed.
db_query("DELETE FROM {locales_target} WHERE language = '%s' AND lid = %d AND plid = %d AND plural = %d", $langcode, $lid, $plid, $plural);
$report['deletes']++;
}
return $lid;
}