3 class SugarTestLangPackCreator
5 public function __construct()
9 public function __destruct()
11 $this->clearLangCache();
15 * Set a string for the app_strings array
18 * @param $value string
20 public function setAppString(
25 $this->_strings['app_strings'][$key] = $value;
29 * Set a string for the app_list_strings array
32 * @param $value string
34 public function setAppListString(
39 $this->_strings['app_list_strings'][$key] = $value;
43 * Set a string for the mod_strings array
46 * @param $value string
47 * @param $module string
49 public function setModString(
55 $this->_strings['mod_strings'][$module][$key] = $value;
59 * Saves the created strings
61 * Here, we cheat the system by storing our string overrides in the sugar_cache where
62 * we normally stored the cached language strings.
64 public function save()
66 $language = $GLOBALS['current_language'];
67 if ( isset($this->_strings['app_strings']) ) {
68 $cache_key = 'app_strings.'.$language;
69 $app_strings = sugar_cache_retrieve($cache_key);
70 if ( empty($app_strings) )
71 $app_strings = return_application_language($language);
72 foreach ( $this->_strings['app_strings'] as $key => $value )
73 $app_strings[$key] = $value;
74 sugar_cache_put($cache_key, $app_strings);
75 $GLOBALS['app_strings'] = $app_strings;
78 if ( isset($this->_strings['app_list_strings']) ) {
79 $cache_key = 'app_list_strings.'.$language;
80 $app_list_strings = sugar_cache_retrieve($cache_key);
81 if ( empty($app_list_strings) )
82 $app_list_strings = return_app_list_strings_language($language);
83 foreach ( $this->_strings['app_list_strings'] as $key => $value )
84 $app_list_strings[$key] = $value;
85 sugar_cache_put($cache_key, $app_list_strings);
86 $GLOBALS['app_list_strings'] = $app_list_strings;
89 if ( isset($this->_strings['mod_strings']) ) {
90 foreach ( $this->_strings['mod_strings'] as $module => $strings ) {
91 $cache_key = "LanguageManager.$module.$language";
92 $mod_strings = sugar_cache_retrieve($cache_key);
93 if ( empty($mod_strings) )
94 $mod_strings = return_module_language($language, $module);
95 foreach ( $strings as $key => $value )
96 $mod_strings[$key] = $value;
97 sugar_cache_put($cache_key, $mod_strings);
103 * Clear the language string cache in sugar_cache, which will get rid of our
104 * language file overrides.
106 protected function clearLangCache()
108 $language = $GLOBALS['current_language'];
110 if ( isset($this->_strings['app_strings']) ) {
111 $cache_key = 'app_strings.'.$language;
112 sugar_cache_clear($cache_key);
115 if ( isset($this->_strings['app_list_strings']) ) {
116 $cache_key = 'app_list_strings.'.$language;
117 sugar_cache_clear($cache_key);
120 if ( isset($this->_strings['mod_strings']) ) {
121 foreach ( $this->_strings['mod_strings'] as $module => $strings ) {
122 $cache_key = "LanguageManager.$module.$language";
123 sugar_cache_clear($cache_key);