function _potx_translation_export in Translation template extractor 7
Same name and namespace in other branches
- 8 potx.inc \_potx_translation_export()
- 5.2 potx.inc \_potx_translation_export()
- 5 potx.inc \_potx_translation_export()
- 6.3 potx.inc \_potx_translation_export()
- 6 potx.inc \_potx_translation_export()
- 6.2 potx.inc \_potx_translation_export()
- 7.3 potx.inc \_potx_translation_export()
- 7.2 potx.inc \_potx_translation_export()
Export translations with a specific language.
Parameters
$translation_export_langcode: Language code if translations should also be exported.
$string: String or singular version if $plural was provided.
$plural: Plural version of singular string.
$api_version: Drupal API version to work with.
1 call to _potx_translation_export()
- _potx_build_files in ./
potx.inc - Creates complete file strings with _potx_store()
File
- ./
potx.inc, line 399 - Extraction API used by the web and command line interface.
Code
function _potx_translation_export($translation_export_langcode, $string, $plural = NULL, $api_version = POTX_API_CURRENT) {
include_once 'includes/locale.inc';
// Stip out slash escapes.
$string = stripcslashes($string);
// Column and table name changed between versions.
$language_column = $api_version > POTX_API_5 ? 'language' : 'locale';
$language_table = $api_version > POTX_API_5 ? 'languages' : 'locales_meta';
if (!isset($plural)) {
// Single string to look translation up for.
if ($translation = db_query("SELECT t.translation FROM {locales_source} s LEFT JOIN {locales_target} t ON t.lid = s.lid WHERE s.source = :source AND t.{$language_column} = :langcode", array(
':source' => $string,
':langcode' => $translation_export_langcode,
))
->fetchField()) {
return 'msgstr ' . _locale_export_string($translation);
}
return "msgstr \"\"\n";
}
else {
// String with plural variants. Fill up source string array first.
$plural = stripcslashes($plural);
$strings = array();
$number_of_plurals = db_query('SELECT plurals FROM {' . $language_table . "} WHERE {$language_column} = :langcode", array(
':langcode' => $translation_export_langcode,
))
->fetchField();
$plural_index = 0;
while ($plural_index < $number_of_plurals) {
if ($plural_index == 0) {
// Add the singular version.
$strings[] = $string;
}
elseif ($plural_index == 1) {
// Only add plural version if required.
$strings[] = $plural;
}
else {
// More plural versions only if required, with the lookup source
// string modified as imported into the database.
$strings[] = str_replace('@count', '@count[' . $plural_index . ']', $plural);
}
$plural_index++;
}
$output = '';
if (count($strings)) {
// Source string array was done, so export translations.
foreach ($strings as $index => $string) {
if ($translation = db_query("SELECT t.translation FROM {locales_source} s LEFT JOIN {locales_target} t ON t.lid = s.lid WHERE s.source = :source AND t.{$language_column} = :langcode", array(
':source' => $string,
':langcode' => $translation_export_langcode,
))
->fetchField()) {
$output .= 'msgstr[' . $index . '] ' . _locale_export_string(_locale_export_remove_plural($translation));
}
else {
$output .= "msgstr[" . $index . "] \"\"\n";
}
}
}
else {
// No plural information was recorded, so export empty placeholders.
$output .= "msgstr[0] \"\"\n";
$output .= "msgstr[1] \"\"\n";
}
return $output;
}
}