function i18nstrings_save_string in Internationalization 5.3
Same name and namespace in other branches
- 5 experimental/i18nstrings.module \i18nstrings_save_string()
- 5.2 experimental/i18nstrings.module \i18nstrings_save_string()
- 6 i18nstrings/i18nstrings.module \i18nstrings_save_string()
Save string for a language
Locale's cache needs refreshing after calling this one. We don't do it here as locale_refresh_cache() is a quite expensive operation.
3 calls to i18nstrings_save_string()
- i18nstrings_admin_form_submit in i18nstrings/
i18nstrings.module - Form submit callback
- i18nstrings_get_string in i18nstrings/
i18nstrings.module - Get string for a language.
- i18nstrings_tt in i18nstrings/
i18nstrings.module - Translate configurable string, and store for l10n client
File
- i18nstrings/
i18nstrings.module, line 154 - Internationalization (i18n) package - translattable strings
Code
function i18nstrings_save_string($strid, $string) {
// This will store the string sources to update or create at the end
if ($source = _i18nstrings_get_source($string, $strid)) {
if (!$source->strid) {
// We have the string, just need to create i18n row
$source->strid = $strid;
$source->paths[] = $strid;
_i18nstrings_save_source($source);
}
elseif ($source->source != $string) {
if (count($source->paths) == 1) {
// This is a unique i18n row, just update locale source
unset($source->strid);
// So i18n row is not updated we add it back 2 lines below
$source->source = $string;
_i18nstrings_save_source($source);
$source->strid = $strid;
}
else {
// Fuck, there are more i18n rows, we need to update this one and create a new one
$update = $source;
$update->paths = array_diff($source->paths, array(
$strid,
));
unset($source->strid);
_i18nstrings_save_source($update);
// Now we save the new one but search before for this other string
if ($search = _i18nstrings_get_source($string)) {
$source = $search;
$source->paths[] = $strid;
}
else {
// String not found so we create a full new one at the end
unset($source->lid);
$source->paths = array(
$strid,
);
}
$source->strid = $strid;
_i18nstrings_save_source($source);
}
}
else {
// Just check in case the strid is not in locale table, this shouldn't happen thoug
if (!in_array($strid, $source->paths)) {
$source->paths[] = $strid;
_i18nstrings_save_source($source);
}
}
}
else {
// Full create
$source = new Stdclass();
$source->strid = $strid;
$source->source = $string;
$source->paths[] = $strid;
_i18nstrings_save_source($source);
}
return $source;
}