19 require_once(BASE.
"wcmf/lib/util/class.Message.php");
20 require_once(BASE.
"wcmf/lib/util/class.InifileParser.php");
51 static $result = array();
54 $baseDir = $directory;
56 if (substr($directory, -1) !=
'/')
58 if (is_dir($directory))
62 while(
false !== ($file = $d->read()))
63 if($file !=
'.' && $file !=
'..')
65 if (is_dir($directory.$file))
66 $this->
getMessages($directory.$file, $pattern, ++$depth);
67 elseif (preg_match($pattern, $file))
70 if (
sizeof($messages) > 0)
72 $key = str_replace($baseDir,
'', $directory.$file);
73 $result[$key] = $messages;
80 $this->_errorMsg =
"The directory '".$directory.
"' does not exist.";
97 if (file_exists($file))
99 $fh = fopen($file,
"r");
100 $content = fread($fh, filesize ($file));
102 preg_match_all(
'/Message->get\(([\'"])(.*?)\\1|Message::get\(([\'"])(.*?)\\3|translate.*? text=([\'"])(.*?)\\5/i', $content, $matchesTmp);
105 foreach(array_merge($matchesTmp[2], $matchesTmp[4], $matchesTmp[6]) as $match)
106 if ($match !=
'' && !in_array($match, $matches))
107 array_push($matches, $match);
108 if (
sizeof($matches) > 0)
128 function createPOFile($projectID, $teamName, $teamEmail, $language, $country, $charset, $filename, $messages)
132 if (($localDir = $parser->getValue(
'localeDir',
'cms')) ===
false)
134 $this->_errorMsg = $parser->getErrorMsg();
137 if (substr($localDir, -1) !=
'/')
140 $languageCode = $language.
'_'.$country;
141 $directory = $localDir.$languageCode.
'/LC_MESSAGES/';
142 if (!file_exists($localDir))
144 if (!file_exists($localDir.$languageCode))
145 mkdir($localDir.$languageCode);
146 if (!file_exists($directory))
149 $file = $directory.$filename.
'.po';
152 if (file_exists($file))
153 rename($file, $file.
".bak");
155 $fh = fopen($file,
"w");
158 $header =
'msgid ""'.
"\n";
159 $header .=
'msgstr ""'.
"\n";
160 $header .=
'"Project-Id-Version: '.$projectID.
'\n"'.
"\n";
161 $header .=
'"POT-Creation-Date: '.date(
"Y-m-d H:iO", mktime()).
'\n"'.
"\n";
162 $header .=
'"PO-Revision-Date: '.date(
"Y-m-d H:iO", mktime()).
'\n"'.
"\n";
163 $header .=
'"Last-Translator: '.$teamName.
' <'.$teamEmail.
'>\n"'.
"\n";
164 $header .=
'"Language-Team: '.$teamName.
' <'.$teamEmail.
'>\n"'.
"\n";
165 $header .=
'"MIME-Version: 1.0\n"'.
"\n";
166 $header .=
'"Content-Type: text/plain; charset='.$charset.
'\n"'.
"\n";
167 $header .=
'"Content-Transfer-Encoding: 8bit\n"'.
"\n";
169 fwrite($fh, $header.
"\n");
172 foreach($messages as $message => $attributes)
173 fwrite($fh,
'#: '.$attributes[
'files'].
"\n".
'msgid "'.$message.
'"'.
"\n".
'msgstr "'.$attributes[
'translation'].
'"'.
"\n\n");
getMessagesFromFile($file)
I18nUtil provides support i18n functionality.
createPOFile($projectID, $teamName, $teamEmail, $language, $country, $charset, $filename, $messages)
getMessages($directory, $pattern, $depth=0)