Odyssey
hcuTranslate.i
1 <?php
2 /*
3  * Polish can cause problems with it's two byte characters. Also, we aren't being consistent on if we are using the ISO or UTF-8 standard.
4  * New flag was added 'html_decode'. When this is set, the msg function will return all string after decoding all &#XXX entity codes. This is
5  * done because browsers seem to work better if these are set, especially in kendo, where it does not decode the entity codes..
6  *
7  * Upon getting ready to have the borwser display the text hcu_displayHtml should be used
8  * mws 12/30/14
9  *
10  */
11 
12 define("HCU_DISPLAY_AS_HTML", 0);
13 define("HCU_DISPLAY_AS_JS", 1);
14 define("HCU_DISPLAY_AS_RAW", 2);
15 
17  var $messages;
18  var $lang;
19  var $html_decode;
20  var $langName;
21  var $js_find;
22  var $combo_replace;
23 
24  // construtor - load the correct language module
25  function __construct($Flang) {
26  if ( !$Flang ) $Flang = "en_US";
27  $includeFile = "hcuTranslate." . $Flang . ".i";
28 
29  include(dirname(__FILE__) . '/../includes/' . $includeFile );
30  // assign the variables from the language module
31  $this->js_find = $js_find;
32  $this->js_replace = $js_replace;
33  $this->lowerChar = $lowerChar;
34  $this->upperChar = $upperChar;
35  $this->messages = $messages;
36 
37  // ** Allow the Loading Config file to set whether to decode all values coming from dictionary
38  // ** Mostly needed for &# encoding
39  $this->html_decode = ($html_decode == 1 ? 1 : 0);
40 
41  // save the language, too
42  $this->lang = $lang;
43  $this->langName = $langName;
44 
45  }
46 
47  function get_lang() {
48  return $this->lang;
49  }
50 
51  function msg($s, $displayType = HCU_DISPLAY_AS_RAW) {
52  /*
53  *
54  * msg may return the message encoded the following ways
55  * NOTE: hcuTranslate.xx_US are all saved with html entities &#xxx; or &word;
56  *
57  * HCU_DISPLAY_AS_JS
58  * This option will return any html entity represented by its \u (unicode) value
59  * this is done with search and replace arrays defining the entities to replace
60  *
61  *
62  * HCU_DISPLAY_AS_RAW
63  * This option will return any html entity represented by its UTF-8 character encoding
64  *
65  * HCU_DISPLAY_AS_HTML
66  * This option will return the entity codes represented with the html entities intact
67  *
68  */
69  if (isset($this->messages[$s])) {
70  if ($displayType == HCU_DISPLAY_AS_JS) {
71  return $this->js_msg($s);
72  } elseif ($displayType == HCU_DISPLAY_AS_RAW) {
73  return html_entity_decode($this->messages[$s], ENT_QUOTES, 'UTF-8');
74  } else {
75  return $this->messages[$s];
76  }
77  } else {
78  error_log("HCU Message error in " . $_SERVER['PHP_SELF'] . ": $this->lang,message:'$s'");
79  }
80  }
81  function js_msg($s) {
82  if (isset($this->messages[$s])) {
83  $js_msg = $this->messages[$s];
84  $js_msg = str_replace(
85  $this->js_find,
86  $this->js_replace,
87  $js_msg);
88  return $js_msg;
89  } else {
90  error_log("HCU Message error in " . $_SERVER['PHP_SELF'] . ": $this->lang,message:'$s'");
91  }
92  }
93  function combo_msg($s, $displayType = HCU_DISPLAY_AS_HTML, $find="", $replace="") {
94  if (isset($this->messages[$s])) {
95  $combo_msg = $this->messages[$s];
96  $combo_msg = str_replace($find,$replace,$combo_msg);
97  if ($displayType == HCU_DISPLAY_AS_JS) {
98 
99  # html entities to unicode for MSIE javascript
100 
101  $combo_msg = str_replace(
102  $this->js_find,
103  $this->js_replace,
104  $combo_msg);
105  } elseif ($displayType == HCU_DISPLAY_AS_RAW) {
106  return html_entity_decode($combo_msg, ENT_QUOTES, 'UTF-8');
107  }
108  return $combo_msg;
109  } else {
110  error_log("HCU Message error in " . $_SERVER['PHP_SELF'] . ": $this->lang,message:'$s'");
111  }
112  }
113  /*
114  * message_decode
115  * this function will return the the full array of messages, however, if the class is setup to use
116  * html_decode, then it will call the necessary functions
117  */
118  function message_decode() {
119 
120  $copyMessage = $this->messages;
121 
122  if ($this->html_decode == 1) {
123  // walk through array, decode the html entities
124  array_walk($copyMessage, function(&$value, $key) {
125  $value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
126  });
127  }
128 
129  return $copyMessage;
130  }
131 }
132