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