Andrew's Web Libraries (AWL)
Translation.php
1 <?php
11 if ( !function_exists('i18n') ) {
54  function i18n($value) {
55  return $value; /* Just pass the value through */
56  }
57 }
58 
59 
60 if ( !function_exists('translate') ) {
64  if ( function_exists('gettext') ) {
65  function translate( $en ) {
66  if ( ! isset($en) || $en == '' ) return $en;
67  $xl = gettext($en);
68  dbg_error_log('I18N','Translated =%s= into =%s=', $en, $xl );
69  return $xl;
70  }
71  }
72  else {
73  function translate( $en ) {
74  return $en;
75  }
76  }
77 }
78 
79 
80 if ( !function_exists('init_gettext') ) {
84  function init_gettext( $domain, $location ) {
85  if ( !function_exists('bindtextdomain') ) return;
86  $location = bindtextdomain( $domain, $location );
87  $codeset = bind_textdomain_codeset( $domain, 'UTF-8' );
88  $domain = textdomain( $domain );
89  dbg_error_log('I18N','Bound domain =%s= to location =%s= using character set =%s=', $domain, $location, $codeset );
90  }
91 }
92 
93 
94 if ( !function_exists('awl_set_locale') ) {
99  function awl_set_locale( $locale ) {
100  global $c;
101 
102  if ( !is_array($locale) && ! preg_match('/^[a-z]{2}(_[A-Z]{2})?\./', $locale ) ) {
103  $locale = array( $locale, $locale.'.UTF-8');
104  }
105  if ( !function_exists('setlocale') ) {
106  dbg_log_array('WARN','No "setlocale()" function? PHP gettext support missing?' );
107  return;
108  }
109  if ( $newlocale = setlocale( LC_ALL, $locale) ) {
110  dbg_error_log('I18N','Set locale to =%s=', $newlocale );
111  $c->current_locale = $newlocale;
112  }
113  else {
114  dbg_log_array('I18N','Unsupported locale: ', $locale, false );
115  }
116  }
117 }
118