52 if (ini_get(
'memory_limit') !=
'-1') ini_set(
'memory_limit',
'-1');
53 error_reporting(E_ALL);
61 if ((php_sapi_name() ==
'cli')) {
62 if (isset($_SERVER[
'argv'][1])) {
63 $SYSTEM_ROOT = $_SERVER[
'argv'][1];
65 $err_msg =
"You need to supply the path to the System Root as the first argument\n";
69 <div style="background-color: red; color: white; font-weight: bold;">
70 You can only run the '.$_SERVER[
'argv'][0].
' script from the command line
75 if (empty($SYSTEM_ROOT)) {
80 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.
'/core/include/init.inc')) {
81 echo
"ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
87 require_once
'Console/Getopt.php';
90 $longopt = Array(
'locale=',
'output=');
92 $con =
new Console_Getopt;
93 $args = $con->readPHPArgv();
95 $options = $con->getopt($args, $shortopt, $longopt);
97 if (is_array($options[0])) {
98 $opt_list = get_console_list($options[0]);
99 $locale_list = $opt_list[
'locale'];
105 if (empty($locale_list)) {
106 echo
"\nWARNING: You did not specify a --locale parameter. This is okay but be aware that all locales will be compiled, which may take a while if you have multiple locales on your system\n\n";
109 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
111 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
114 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
115 echo
"Failed login in as root user\n";
120 require_once $SYSTEM_ROOT.
'/install/install.inc';
121 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
122 require_once
'XML/Tree.php';
125 $string_locales = Array();
126 $error_locales = Array();
127 $message_locales = Array();
128 $all_screens = Array();
134 if (!empty($opt_list[
'dir'])) {
135 $locale_backup_dir = $opt_list[
'dir'];
137 $locale_backup_dir = SQ_DATA_PATH.
'/temp/locale_backup';
140 create_directory($locale_backup_dir);
143 $asset_types = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTypes();
146 array_unshift($asset_types, Array(
147 'type_code' =>
'asset',
148 'dir' =>
'core/include/asset_edit',
149 'name' =>
'Base Asset',
152 foreach($GLOBALS[
'SQ_SYSTEM']->getInstalledPackages() as $package) {
153 if ($package[
'code_name'] ==
'__core__')
continue;
154 array_unshift($asset_types, Array(
156 'dir' =>
'packages/'.$package[
'code_name'],
157 'name' => $package[
'name'],
164 array_unshift($asset_types, Array(
167 'name' =>
'Global Strings',
170 $locale_names = array_keys($locale_list);
171 foreach($locale_names as $locale) {
172 $locale_parts = $GLOBALS[
'SQ_SYSTEM']->lm->getCumulativeLocaleParts($locale);
173 foreach($locale_parts as $locale_part) {
174 if (!in_array($locale_part, $locale_names)) {
175 $locale_list[$locale_part] = $locale_list[$locale];
180 foreach ($asset_types as $asset_type) {
182 $type_code = $asset_type[
'type_code'];
184 $local_screen_dir = SQ_DATA_PATH.
'/private/asset_types/'.$type_code.
'/localised_screens';
187 $base_path = SQ_SYSTEM_ROOT.
'/'.$asset_type[
'dir'].
'/locale';
188 $dirs_to_read = Array($base_path);
190 while (!empty($dirs_to_read)) {
191 $dir_read = array_shift($dirs_to_read);
193 $d = @opendir($dir_read);
198 $locale_name = str_replace($base_path.
'/',
'', $dir_read);
199 if (($slash_pos = strpos($locale_name,
'/')) !==
false) {
200 $locale_name{$slash_pos} =
'_';
201 if (($slash_pos = strpos($locale_name,
'/')) !==
false) {
202 $locale_name{$slash_pos} =
'@';
206 while (
false !== ($entry = readdir($d))) {
207 if (($entry ==
'..') || ($entry ==
'.') || ($entry ==
'CVS'))
continue;
209 if (is_dir($dir_read.
'/'.$entry)) {
210 if (!in_array($dir_read.
'/'.$entry, $dirs_to_read)) {
211 $dirs_to_read[] = $dir_read.
'/'.$entry;
216 $locale_parts = $GLOBALS[
'SQ_SYSTEM']->lm->getCumulativeLocaleParts($locale_name);
218 if (preg_match(
'|lang\_((static_)?screen\_.*)\.xml|', $entry, $matches)) {
220 if (!empty($locale_list) && (!in_array($locale_name, array_keys($locale_list))
221 || (!in_array(
'all', $locale_list[$locale_name])
222 && !in_array(
'screens', $locale_list[$locale_name])))) {
226 if (!isset($screens[$locale_name])) {
227 $screens[$locale_name] = Array();
230 $screens[$locale_name][] = $dir_read.
'/lang_'.$matches[1].
'.xml';
232 }
else if (preg_match(
'|lang\_strings\.xml|', $entry, $matches)) {
234 foreach($locale_parts as $locale_part) {
235 if (!in_array($locale_part, $string_locales)) {
236 $string_locales[$locale_part][] = $base_path;
240 }
else if (preg_match(
'|lang\_errors\.xml|', $entry, $matches)) {
242 foreach($locale_parts as $locale_part) {
243 if (!in_array($locale_part, $error_locales)) {
244 $error_locales[$locale_part][] = $base_path;
248 }
else if (preg_match(
'|lang\_messages\.xml|', $entry, $matches)) {
250 foreach($locale_parts as $locale_part) {
251 if (!in_array($locale_part, $message_locales)) {
252 $message_locales[$locale_part][] = $base_path;
263 $d = @opendir(SQ_SYSTEM_ROOT.
'/'.$asset_type[
'dir']);
266 while (
false !== ($entry = readdir($d))) {
267 if (preg_match(
'|edit\_interface\_((static_)?screen\_.*).xml|', $entry, $matches)) {
268 $all_screens[] = $base_path.
'/'.$entry;
279 foreach($string_locales as $locale => $loc_files) {
280 $loc_files = array_unique($loc_files);
281 if (!empty($locale_list) && !in_array(
'strings', array_get_index($locale_list, $locale, Array())) &&
282 !in_array(
'all', array_get_index($locale_list, $locale, Array()))) {
285 $string_file =
'<?xml version="1.0" ?>'.
"\n";
286 $string_file .=
'<files locale="'.$locale.
'">'.
"\n";
288 foreach($loc_files as $loc_file) {
289 $string_file .=
'<file source="'.substr(str_replace(SQ_SYSTEM_ROOT,
'', $loc_file),1).
'" name="lang_strings.xml">'.
"\n";
290 $string_file .= str_replace(
'<?xml version="1.0" ?>',
'',
291 file_get_contents($loc_file.
'/'.str_replace(
'_',
'/', str_replace(
'@',
'/', $locale)).
'/lang_strings.xml').
"\n");
292 $string_file .=
'</file>'.
"\n";
295 $string_file .=
'</files>'.
"\n";
297 create_directory($locale_backup_dir.
'/'.$locale);
298 string_to_file($string_file, $locale_backup_dir.
'/'.$locale.
'/strings.xml');
303 $error_locales = array_unique($error_locales);
304 foreach($error_locales as $locale => $loc_files) {
305 $loc_files = array_unique($loc_files);
306 if (!empty($locale_list) && !in_array(
'errors', array_get_index($locale_list, $locale, Array())) &&
307 !in_array(
'all', array_get_index($locale_list, $locale, Array()))) {
310 $error_file =
'<?xml version="1.0" ?>'.
"\n";
311 $error_file .=
'<files locale="'.$locale.
'">'.
"\n";
313 foreach($loc_files as $loc_file) {
314 $error_file .=
'<file source="'.substr(str_replace(SQ_SYSTEM_ROOT,
'', $loc_file),1).
'" name="lang_errors.xml">'.
"\n";
315 $error_file .= str_replace(
'<?xml version="1.0" ?>',
'',
316 file_get_contents($loc_file.
'/'.str_replace(
'_',
'/', str_replace(
'@',
'/', $locale)).
'/lang_errors.xml').
"\n");
319 $error_file .=
'</file>'.
"\n";
322 $error_file .=
'</files>'.
"\n";
324 create_directory($locale_backup_dir.
'/'.$locale);
325 string_to_file($error_file, $locale_backup_dir.
'/'.$locale.
'/errors.xml');
330 foreach($message_locales as $locale => $loc_files) {
331 $loc_files = array_unique($loc_files);
332 if (!empty($locale_list) && !in_array(
'messages', array_get_index($locale_list, $locale, Array())) &&
333 !in_array(
'all', array_get_index($locale_list, $locale, Array()))) {
336 $message_file =
'<?xml version="1.0" ?>'.
"\n";
337 $message_file .=
'<files locale="'.$locale.
'">'.
"\n";
339 foreach($loc_files as $loc_file) {
340 $message_file .=
'<file source="'.substr(str_replace(SQ_SYSTEM_ROOT,
'', $loc_file),1).
'" name="lang_messages.xml">'.
"\n";
341 $message_file .= str_replace(
'<?xml version="1.0" ?>',
'',
342 file_get_contents($loc_file.
'/'.str_replace(
'_',
'/', str_replace(
'@',
'/', $locale)).
'/lang_messages.xml').
"\n");
343 $message_file .=
'</file>'.
"\n";
346 $message_file .=
'</files>'.
"\n";
348 create_directory($locale_backup_dir.
'/'.$locale);
349 string_to_file($message_file, $locale_backup_dir.
'/'.$locale.
'/internal_messages.xml');
353 foreach($screens as $locale => $loc_files) {
354 $loc_files = array_unique($loc_files);
355 if (!empty($locale_list) && !in_array(
'screens', array_get_index($locale_list, $locale, Array())) &&
356 !in_array(
'all', array_get_index($locale_list, $locale, Array()))) {
359 $message_file =
'<?xml version="1.0" ?>'.
"\n";
360 $message_file .=
'<files locale="'.$locale.
'">'.
"\n";
362 foreach($loc_files as $loc_file) {
363 $folder = substr($loc_file, 0, strpos($loc_file,
'/locale/') + strlen(
'/locale'));
364 $file_name = substr($loc_file, strrpos($loc_file,
'/') + 1);
366 $message_file .=
'<file source="'.substr(str_replace(SQ_SYSTEM_ROOT,
'', $folder),1).
'" name="'.$file_name.
'">'.
"\n";
367 $message_file .= str_replace(
'<?xml version="1.0" ?>',
'',
368 file_get_contents($loc_file).
"\n");
369 $message_file .=
'</file>'.
"\n";
372 $message_file .=
'</files>'.
"\n";
374 create_directory($locale_backup_dir.
'/'.$locale);
375 string_to_file($message_file, $locale_backup_dir.
'/'.$locale.
'/screens.xml');
393 function get_console_list($options)
395 $list = Array(
'locale' => Array(),
'dir' =>
'');
397 foreach ($options as $option) {
399 if (!isset($option[0]) || !isset($option[1]))
continue;
404 $parts = explode(
'-', $option[1]);
407 if ((count($parts) == 2) && strlen($parts[1])) {
408 $types = explode(
',', $parts[1]);
410 $types = Array(
'all');
413 $list[
'locale'][$parts[0]] = $types;
417 $list[
'dir'] = $option[1];