14 require(dirname(dirname(dirname(dirname(__FILE__)))) .
'/tools/bootstrap.inc.php');
31 $this->sourceXmlFile = array_shift(
$argv);
32 $this->poFile = array_shift(
$argv);
34 if (empty($this->sourceXmlFile) || !file_exists($this->sourceXmlFile)) {
39 if (empty($this->poFile)) {
49 echo
"Script to convert XML email file to PO format\n"
50 .
"Usage: {$this->scriptName} input-locale-file.xml output-file.po\n";
59 $localeData = array();
61 $data = $xmlDao->parse($filename, array(
'email_texts',
'email_text',
'subject',
'body',
'description'));
62 if (!$data)
return null;
64 $locale = $data->getAttribute(
'locale');
66 foreach ($data->getChildren() as $emailNode) {
67 $key = $emailNode->getAttribute(
'key');
69 $subject = $emailNode->getChildValue(
'subject');
70 $body = $emailNode->getChildValue(
'body');
71 $description = $emailNode->getChildValue(
'description');
73 $localeData[$key] = array(
74 'subject' => $emailNode->getChildValue(
'subject'),
75 'body' => $emailNode->getChildValue(
'body'),
76 'description' => $emailNode->getChildValue(
'description'),
87 $localeData = array();
91 if (!$sourceData)
throw new Exception(
'Unable to load source file ' . $this->sourceXmlFile);
93 import(
'lib.pkp.classes.file.EditableEmailFile');
94 $editableEmailFile =
new EditableEmailFile($locale, $this->sourceXmlFile);
96 $translations = new \Gettext\Translations();
97 foreach ($sourceData as $emailKey => $sourceEmailData) {
99 $camelEmailKey = str_replace(
' ',
'', ucwords(str_replace(
'_',
' ', strtolower($emailKey))));
100 $camelEmailKey[0] = strtolower($camelEmailKey[0]);
102 foreach (array(
'subject',
'body',
'description') as $elementName) {
103 $elementValue = $sourceEmailData[$elementName];
104 $key =
"emails.$camelEmailKey.$elementName";
106 $translation = new \Gettext\Translation(
'', $key);
107 $translation->setTranslation($elementValue);
108 $translations->append($translation);
111 $editableEmailFile->update(
113 "{translate key=\"emails.$camelEmailKey.subject\"}",
114 "{translate key=\"emails.$camelEmailKey.body\"}",
115 "{translate key=\"emails.$camelEmailKey.description\"}"
118 $editableEmailFile->write();
120 $translations->toPoFile($this->poFile);