24 private static $result = [];
25 private static $baseDir =
'';
37 public static function getMessages($directory, $exclude, $pattern, $depth=0) {
40 self::$baseDir = $directory;
42 if (substr($directory, -1) !=
'/') {
45 if (is_dir($directory)) {
48 while(
false !== ($file = $d->read())) {
49 if($file !=
'.' && $file !=
'..' && !in_array($file, $exclude)) {
50 if (is_dir($directory.$file)) {
53 elseif (preg_match($pattern, $file)) {
55 if (
sizeof($messages) > 0) {
56 $key = str_replace(self::$baseDir,
'', $directory.$file);
57 self::$result[$key] = $messages;
84 if (file_exists($file) && realpath($file) != __FILE__) {
85 $fh = fopen($file,
"r");
86 $content = fread($fh, filesize ($file));
89 '->getText\(([\'"])(.*?)\\1',
90 'Dict\.translate\(([\'"])(.*?)\\3',
91 '\{translate:(.*?)[\|\}]',
92 '\{translate.*? text=([\'"])(.*?)\\6',
94 preg_match_all(
'/'.join(
'|', $messagePatterns).
'/i', $content, $matchesTmp);
97 foreach(array_merge($matchesTmp[2], $matchesTmp[4], $matchesTmp[5], $matchesTmp[7]) as $match) {
98 if ($match !=
'' && !in_array($match, $matches)) {
102 if (
sizeof($matches) > 0) {
123 $localeDir = $config->getDirectoryValue(
'localeDir',
'application');
124 $fileUtil->mkdirRec($localeDir);
125 $file = $localeDir.
'messages_'.$language.
'.php';
128 if (file_exists($file)) {
129 rename($file, $file.
".bak");
131 $fh = fopen($file,
"w");
136 \$messages_{$language} = [];
137 \$messages_{$language}[
''] =
'';
139 fwrite($fh, $header.
"\n");
142 foreach($messages as $message => $attributes) {
143 $lines =
'// file(s): '.$attributes[
'files'].
"\n";
144 $lines .=
"\$messages_".$language.
"['".str_replace(
"'",
"\'", $message).
"'] = '".str_replace(
"'",
"\'", $attributes[
'translation']).
"';".
"\n";
152 fwrite($fh, $footer.
"\n");
IllegalArgumentException signals an exception in method arguments.
static createPHPLanguageFile($language, $messages)
Create a message file for use with the Message class.
I18nUtil provides support i18n functionality.
static getMessagesFromFile($file)
Get all messages from a file.
FileUtil provides basic support for file functionality like HTTP file upload.
static getInstance($name, $dynamicConfiguration=[])
static getMessages($directory, $exclude, $pattern, $depth=0)
Get all messages from a directory recursively.
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...