18 require_once SQ_FUDGE_PATH.
'/general/text.inc';
42 public $locale_stack = Array();
51 public $_strings = Array();
60 public $_errors = Array();
69 public $_internal_messages = Array();
79 private $_assets_included = Array();
89 private $_packages_included = Array();
99 private $_core_included = Array();
124 if (array_get_index($this->_tmp,
'strings_modified', FALSE) && isset($GLOBALS[
'SQ_SYSTEM'])) {
125 $this->locale_stack = Array();
127 $deja_vu = $GLOBALS[
'SQ_SYSTEM']->getDejaVu();
129 $deja_vu->remember(SQ_DEJA_VU_LOCALE, NULL, $this);
146 if (count($this->locale_stack) <= 0)
return FALSE;
147 return $this->locale_stack[0];
163 if (is_null($locale_code)) {
166 require SQ_FUDGE_PATH.
'/standards_lists/locales.inc';
167 return array_get_index($standards_lists_locales, $locale_code,
'Unknown');
182 array_unshift($this->locale_stack, $locale);
198 if (count($this->locale_stack) <= 0)
return FALSE;
199 array_shift($this->locale_stack);
219 $locale_parts = Array(NULL, NULL, NULL);
221 preg_match(
'|([A-Za-z]{2})(\_([A-Za-z]{2})(\@([A-Za-z]+))?)?|', $locale, $matches);
228 switch (count($matches)) {
230 $locale_parts[2] = $matches[5];
234 $locale_parts[1] = $matches[3];
238 $locale_parts[0] = $matches[1];
242 trigger_localised_error(
'SYS0193', E_USER_WARNING, $locale);
247 return $locale_parts;
271 $cum_locale_parts = Array();
272 $cum_locale_parts[] = $locale_parts[0];
274 if (count($cum_locale_parts) >= 2) {
275 $cum_locale_parts[] = $cum_locale_parts[0].$lang_sep.$locale_parts[1];
277 if (count($cum_locale_parts) >= 3) {
278 $cum_locale_parts[] = $cum_locale_parts[1].$var_sep.$locale_parts[2];
282 return $cum_locale_parts;
300 if (!is_array($func_args = func_get_arg(1))) {
301 $func_args = func_get_args();
302 $func_args = array_slice($func_args,1);
305 if (!isset($this->_strings[$locale])) {
306 return "Source string for $string_code not found";
309 if (!isset($this->_strings[$locale][$string_code])) {
310 return "Source string for $string_code not found for locale $locale";
313 return vsprintf($this->_strings[$locale][$string_code],$func_args);
329 if (!isset($this->_assets_included[$type_code])) {
330 $this->_assets_included[$type_code] = Array();
333 if ($locale == NULL) {
338 if (!array_get_index($this->_assets_included[$type_code], $locale, FALSE)) {
339 $this->_tmp[
'strings_modified'] = TRUE;
340 $this->_assets_included[$type_code][$locale] = TRUE;
343 if ($type_code !=
'asset') {
344 $asset_dir = str_replace(
'\\',
'/', SQ_SYSTEM_ROOT.
'/'.$GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($type_code,
'dir'));
346 if (strpos($asset_dir, str_replace(
'\\',
'/', SQ_CORE_PACKAGE_PATH)) !== FALSE) {
349 $asset_dir = str_replace(str_replace(
'\\',
'/', SQ_PACKAGES_PATH).
'/',
'', $asset_dir);
350 $package = substr($asset_dir, 0, strpos($asset_dir,
'/'));
356 $locales = Array($lang);
357 if (!empty($country)) {
358 $locales[] = $lang.
'_'.$country;
359 if (!empty($variant)) {
360 $locales[] = $lang.
'_'.$country.
'@'.$variant;
364 foreach ($locales as $this_locale) {
365 $file = SQ_DATA_PATH.
'/private/asset_types/'.$type_code.
'/strings.'.$this_locale;
367 if (is_file($file)) {
368 $strings = unserialize(file_get_contents($file));
370 if (!isset($this->_strings[$locale])) {
371 $this->_strings[$locale] = Array();
373 $this->_strings[$locale] = array_merge($this->_strings[$locale], $strings);
392 if (!isset($this->_packages_included[$package_name])) {
393 $this->_packages_included[$package_name] = Array();
396 if ($locale == NULL) {
400 if (!array_get_index($this->_packages_included[$package_name], $locale, FALSE)) {
401 $this->_tmp[
'strings_modified'] = TRUE;
402 $this->_packages_included[$package_name][$locale] = TRUE;
405 $locales = Array($lang);
406 if (!empty($country)) {
407 $locales[] = $lang.
'_'.$country;
408 if (!empty($variant)) {
409 $locales[] = $lang.
'_'.$country.
'@'.$variant;
413 foreach ($locales as $this_locale) {
414 $file = SQ_DATA_PATH.
'/private/packages/'.$package_name.
'/strings.'.$this_locale;
415 if (file_exists($file)) {
416 $strings = unserialize(file_get_contents($file));
418 if (!isset($this->_strings[$locale])) {
419 $this->_strings[$locale] = Array();
421 $this->_strings[$locale] = array_merge($this->_strings[$locale], $strings);
424 $file = SQ_DATA_PATH.
'/private/packages/'.$package_name.
'/errors.'.$this_locale;
425 if (is_file($file)) {
426 $strings = unserialize(file_get_contents($file));
428 if (!isset($this->_errors[$locale])) {
429 $this->_errors[$locale] = Array();
431 $this->_errors[$locale] = array_merge($this->_errors[$locale], $strings);
434 $file = SQ_DATA_PATH.
'/private/packages/'.$package_name.
'/internal_messages.'.$this_locale;
435 if (is_file($file)) {
436 $strings = unserialize(file_get_contents($file));
438 if (!isset($this->_internal_messages[$locale])) {
439 $this->_internal_messages[$locale] = Array();
441 $this->_internal_messages[$locale] = array_merge($this->_internal_messages[$locale], $strings);
459 if ($locale == NULL) {
463 if (!array_get_index($this->_core_included, $locale, FALSE)) {
464 $this->_tmp[
'strings_modified'] = TRUE;
465 $this->_core_included[$locale] = TRUE;
468 $locales = Array($lang);
469 if (!empty($country)) {
470 $locales[] = $lang.
'_'.$country;
471 if (!empty($variant)) {
472 $locales[] = $lang.
'_'.$country.
'@'.$variant;
476 foreach ($locales as $this_locale) {
477 $file = SQ_DATA_PATH.
'/private/system/core/strings.'.$this_locale;
478 if (is_file($file)) {
479 $strings = unserialize(file_get_contents($file));
481 if (!isset($this->_strings[$locale])) {
482 $this->_strings[$locale] = Array();
484 $this->_strings[$locale] = array_merge($this->_strings[$locale], $strings);
487 $file = SQ_DATA_PATH.
'/private/system/core/errors.'.$this_locale;
488 if (is_file($file)) {
489 $strings = unserialize(file_get_contents($file));
491 if (!isset($this->_errors[$locale])) {
492 $this->_errors[$locale] = Array();
494 $this->_errors[$locale] = array_merge($this->_errors[$locale], $strings);
497 $file = SQ_DATA_PATH.
'/private/system/core/internal_messages.'.$this_locale;
498 if (is_file($file)) {
499 $strings = unserialize(file_get_contents($file));
501 if (!isset($this->_internal_messages[$locale])) {
502 $this->_internal_messages[$locale] = Array();
504 $this->_internal_messages[$locale] = array_merge($this->_internal_messages[$locale], $strings);
531 if (($error_level != E_USER_ERROR) && ($error_level != E_USER_WARNING) && ($error_level != E_USER_NOTICE)) {
532 trigger_error(
'Invalid error level passed when raising error ['.$code.
']: '.$error_level, E_USER_WARNING);
533 $error_level = E_USER_ERROR;
539 if (func_num_args() == 2) {
540 $func_args = Array();
541 }
else if (!is_array($func_args = func_get_arg(2))) {
542 $func_args = func_get_args();
543 $func_args = array_slice($func_args,2);
547 trigger_error($error_msg, $error_level);
567 if (func_num_args() == 1) {
568 $func_args = Array();
569 }
else if (!is_array($func_args = func_get_arg(1))) {
570 $func_args = func_get_args();
571 $func_args = array_slice($func_args,1);
575 if (!isset($this->_errors[$locale])) {
579 if (!isset($this->_errors[$locale][$code])) {
584 $error_msg = vsprintf($this->_errors[$locale][$code], $func_args).
' ['.$code.
']';
586 $error_msg =
'Error text not found for this code and locale ['.$code.
']';
587 if (!empty($func_args)) {
588 $error_msg .=
"\n".var_export($func_args, 1);
609 if (is_null($locale)) {
614 if (!isset($this->_internal_messages[$locale])) {
618 if (!isset($this->_internal_messages[$locale][$type])) {
623 $subject = $this->_internal_messages[$locale][$type][
'subject'];
624 replace_keywords($subject, $keywords);
626 $subject =
'Internal message translation not found for this code and locale ['.$type.
']';
646 if (is_null($locale)) {
651 if (!isset($this->_internal_messages[$locale])) {
655 if (!isset($this->_internal_messages[$locale][$type])) {
660 $body = $this->_internal_messages[$locale][$type][
'body'];
661 replace_keywords($body, $keywords);
663 $body =
'Internal message translation not found for this code and locale ['.$type.
']';
679 $res = Array(sq_web_path(
'lib').
'/js/translation.js');
680 list($lang, $country, $variant) = $this->
getLocaleParts($GLOBALS[
'SQ_SYSTEM']->lm->getCurrentLocale());
681 if (file_exists(SQ_DATA_PATH.
'/public/system/core/js_strings.'.$lang.
'.js')) {
682 $res[] = sq_web_path(
'data').
'/system/core/js_strings.'.$lang.
'.js';
684 if (!empty($country)) {
685 if (file_exists(SQ_DATA_PATH.
'/public/system/core/js_strings.'.$lang.
'_'.$country.
'.js')) {
686 $res[] = sq_web_path(
'data').
'/system/core/js_strings.'.$lang.
'_'.$country.
'.js';
689 if (!empty($variant)) {
690 if (file_exists(SQ_DATA_PATH.
'/public/system/core/js_strings.'.$lang.
'_'.$country.
'@'.$variant.
'.js')) {
691 $res[] = sq_web_path(
'data').
'/system/core/js_strings.'.$lang.
'_'.$country.
'@'.$variant.
'.js';