Back to index

awl  0.53
Translation.php
Go to the documentation of this file.
00001 <?php
00011 if ( !function_exists('i18n') ) {
00054   function i18n($value) {
00055     return $value;  /* Just pass the value through */
00056   }
00057 }
00058 
00059 
00060 if ( !function_exists('translate') ) {
00064   if ( function_exists('gettext') ) {
00065     function translate( $en ) {
00066       if ( ! isset($en) || $en == '' ) return $en;
00067       $xl = gettext($en);
00068       dbg_error_log('I18N','Translated =%s= into =%s=', $en, $xl );
00069       return $xl;
00070     }
00071   }
00072   else {
00073     function translate( $en ) {
00074       return $en;
00075     }
00076   }
00077 }
00078 
00079 
00080 if ( !function_exists('init_gettext') ) {
00084   function init_gettext( $domain, $location ) {
00085     if ( !function_exists('bindtextdomain') ) return;
00086     bindtextdomain( $domain, $location );
00087     $codeset = bind_textdomain_codeset( $domain, 'UTF-8' );
00088     textdomain( $domain );
00089     dbg_error_log('I18N','Bound domain =%s= to location =%s= using character set =%s=', $domain, $location, $codeset );
00090   }
00091 }
00092 
00093 
00094 if ( !function_exists('awl_set_locale') ) {
00099   function awl_set_locale( $locale ) {
00100     global $c;
00101 
00102     if ( !is_array($locale) && ! preg_match('/^[a-z]{2}(_[A-Z]{2})?\./', $locale ) ) {
00103       $locale = array( $locale, $locale.'.UTF-8');
00104     }
00105     if ( !function_exists('setlocale') ) {
00106       dbg_log_array('WARN','No "setlocale()" function?  PHP gettext support missing?' );
00107       return;
00108     }
00109     if ( $newlocale = setlocale( LC_ALL, $locale) ) {
00110       dbg_error_log('I18N','Set locale to =%s=', $newlocale );
00111       $c->current_locale = $newlocale;
00112     }
00113     else {
00114       dbg_log_array('I18N','Unsupported locale: ', $locale, false );
00115     }
00116   }
00117 }
00118