function _locale_export_po_generate
Generates the PO(T) file contents for given strings.
Parameters
$language: Language object to generate the output for, or NULL if generating translation template.
$strings: Array of strings to export. See _locale_export_get_strings() on how it should be formatted.
$header: The header portion to use for the output file. Defaults are provided for PO and POT files.
Related topics
1 call to _locale_export_po_generate()
- locale_translate_export_po_form_submit in modules/
locale/ locale.admin.inc - Process a translation (or template) export form submission.
File
-
includes/
locale.inc, line 1693
Code
function _locale_export_po_generate($language = NULL, $strings = array(), $header = NULL) {
global $user;
if (!isset($header)) {
if (isset($language)) {
$header = '# ' . $language->name . ' translation of ' . variable_get('site_name', 'Drupal') . "\n";
$header .= '# Generated by ' . $user->name . ' <' . $user->mail . ">\n";
$header .= "#\n";
$header .= "msgid \"\"\n";
$header .= "msgstr \"\"\n";
$header .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
$header .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
$header .= "\"PO-Revision-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
$header .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
$header .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
$header .= "\"MIME-Version: 1.0\\n\"\n";
$header .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
$header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
if ($language->formula && $language->plurals) {
$header .= "\"Plural-Forms: nplurals=" . $language->plurals . "; plural=" . strtr($language->formula, array(
'$' => '',
)) . ";\\n\"\n";
}
}
else {
$header = "# LANGUAGE translation of PROJECT\n";
$header .= "# Copyright (c) YEAR NAME <EMAIL@ADDRESS>\n";
$header .= "#\n";
$header .= "msgid \"\"\n";
$header .= "msgstr \"\"\n";
$header .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
$header .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
$header .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n";
$header .= "\"Last-Translator: NAME <EMAIL@ADDRESS>\\n\"\n";
$header .= "\"Language-Team: LANGUAGE <EMAIL@ADDRESS>\\n\"\n";
$header .= "\"MIME-Version: 1.0\\n\"\n";
$header .= "\"Content-Type: text/plain; charset=utf-8\\n\"\n";
$header .= "\"Content-Transfer-Encoding: 8bit\\n\"\n";
$header .= "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n";
}
}
$output = $header . "\n";
foreach ($strings as $lid => $string) {
// Only process non-children, children are output below their parent.
if (!isset($string['child'])) {
if ($string['comment']) {
$output .= '#: ' . $string['comment'] . "\n";
}
if (!empty($string['context'])) {
$output .= 'msgctxt ' . _locale_export_string($string['context']);
}
$output .= 'msgid ' . _locale_export_string($string['source']);
if (!empty($string['plural'])) {
$plural = $string['plural'];
$output .= 'msgid_plural ' . _locale_export_string($strings[$plural]['source']);
if (isset($language)) {
$translation = $string['translation'];
for ($i = 0; $i < $language->plurals; $i++) {
$output .= 'msgstr[' . $i . '] ' . _locale_export_string($translation);
if ($plural) {
$translation = _locale_export_remove_plural($strings[$plural]['translation']);
$plural = isset($strings[$plural]['plural']) ? $strings[$plural]['plural'] : 0;
}
else {
$translation = '';
}
}
}
else {
$output .= 'msgstr[0] ""' . "\n";
$output .= 'msgstr[1] ""' . "\n";
}
}
else {
$output .= 'msgstr ' . _locale_export_string($string['translation']);
}
$output .= "\n";
}
}
return $output;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.