Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cI18n

Functions

  • i18n
  • i18nEmulateGettext
  • i18nGetAvailableLanguages
  • i18nInit
  • i18nMatchBrowserAccept
  • i18nRegisterDomain
  • i18nStripAcceptLanguages
  • mi18n
  • trans
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * Defines the I18N CONTENIDO functions
  4:  *
  5:  * @package          Core
  6:  * @subpackage       I18N
  7:  * @version          SVN Revision $Rev:$
  8:  *
  9:  * @author           Timo Hummel
 10:  * @copyright        four for business AG <www.4fb.de>
 11:  * @license          http://www.contenido.org/license/LIZENZ.txt
 12:  * @link             http://www.4fb.de
 13:  * @link             http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * gettext wrapper (for future extensions).
 20:  * Usage:
 21:  * trans('Your text which has to be translated');
 22:  *
 23:  * @param $string string The string to translate
 24:  * @return string Returns the translation
 25:  */
 26: function trans($string) {
 27:     return cI18n::__($string);
 28: }
 29: 
 30: /**
 31:  * gettext wrapper (for future extensions).
 32:  * Usage:
 33:  * i18n('Your text which has to be translated');
 34:  *
 35:  * @param string $string The string to translate
 36:  * @param string $domain The domain to look up
 37:  * @return string Returns the translation
 38:  */
 39: function i18n($string, $domain = 'contenido') {
 40:     return cI18n::__($string, $domain);
 41: }
 42: 
 43: /**
 44:  * Emulates GNU gettext
 45:  *
 46:  * @param string $string The string to translate
 47:  * @param string $domain The domain to look up
 48:  * @return string Returns the translation
 49:  */
 50: function i18nEmulateGettext($string, $domain = 'contenido') {
 51:     return cI18n::emulateGettext($string, $domain);
 52: }
 53: 
 54: /**
 55:  * Initializes the i18n stuff.
 56:  *
 57:  * @param string $localePath Path to the locales
 58:  * @param string $langCode Language code to set
 59:  * @param string $domain Language domain
 60:  */
 61: function i18nInit($localePath, $langCode, $domain = 'contenido') {
 62:     cI18n::init($localePath, $langCode, $domain);
 63: }
 64: 
 65: /**
 66:  * Registers a new i18n domain.
 67:  *
 68:  * @param string $localePath Path to the locales
 69:  * @param string $domain Domain to bind to
 70:  * @return string Returns the translation
 71:  */
 72: function i18nRegisterDomain($domain, $localePath) {
 73:     cI18n::registerDomain($domain, $localePath);
 74: }
 75: 
 76: /**
 77:  * Strips all unnecessary information from the $accept string.
 78:  * Example: de,nl;q=0.7,en-us;q=0.3 would become an array with de,nl,en-us
 79:  *
 80:  * @param string $accept Comma searated list of languages to accept
 81:  * @return array array with the short form of the accept languages
 82:  */
 83: function i18nStripAcceptLanguages($accept) {
 84:     $languages = explode(',', $accept);
 85:     $shortLanguages = array();
 86:     foreach ($languages as $value) {
 87:         $components = explode(';', $value);
 88:         $shortLanguages[] = $components[0];
 89:     }
 90: 
 91:     return $shortLanguages;
 92: }
 93: 
 94: /**
 95:  * Tries to match the language given by $accept to
 96:  * one of the languages in the system.
 97:  *
 98:  * @param string $accept Language to accept
 99:  * @return string The locale key for the given accept string
100:  */
101: function i18nMatchBrowserAccept($accept) {
102:     $available_languages = i18nGetAvailableLanguages();
103: 
104:     // Try to match the whole accept string
105:     foreach ($available_languages as $key => $value) {
106:         list($country, $lang, $encoding, $shortaccept) = $value;
107:         if ($accept == $shortaccept) {
108:             return $key;
109:         }
110:     }
111: 
112:     /*
113:      * Whoops, we are still here. Let's match the stripped-down string. Example:
114:      * de-ch isn't in the list. Cut it down after the '-' to 'de' which should
115:      * be in the list.
116:      */
117:     $accept = substr($accept, 0, 2);
118:     foreach ($available_languages as $key => $value) {
119:         list($country, $lang, $encoding, $shortaccept) = $value;
120:         if ($accept == $shortaccept) {
121:             return $key;
122:         }
123:     }
124: 
125:     // / Whoops, still here? Seems that we didn't find any language. Return the
126:     // default (german, yikes)
127:     return false;
128: }
129: 
130: /**
131:  * Returns the available_languages array to prevent globals.
132:  *
133:  * @return array All available languages
134:  */
135: function i18nGetAvailableLanguages() {
136:     /*
137:      * array notes: First field: Language Second field: Country Third field:
138:      * ISO-Encoding Fourth field: Browser accept mapping Fifth field: SPAW
139:      * language
140:      */
141:     $aLanguages = array(
142:         'ar_AA' => array(
143:             'Arabic',
144:             'Arabic Countries',
145:             'ISO8859-6',
146:             'ar',
147:             'en'
148:         ),
149:         'be_BY' => array(
150:             'Byelorussian',
151:             'Belarus',
152:             'ISO8859-5',
153:             'be',
154:             'en'
155:         ),
156:         'bg_BG' => array(
157:             'Bulgarian',
158:             'Bulgaria',
159:             'ISO8859-5',
160:             'bg',
161:             'en'
162:         ),
163:         'cs_CZ' => array(
164:             'Czech',
165:             'Czech Republic',
166:             'ISO8859-2',
167:             'cs',
168:             'cz'
169:         ),
170:         'da_DK' => array(
171:             'Danish',
172:             'Denmark',
173:             'ISO8859-1',
174:             'da',
175:             'dk'
176:         ),
177:         'de_CH' => array(
178:             'German',
179:             'Switzerland',
180:             'ISO8859-1',
181:             'de-ch',
182:             'de'
183:         ),
184:         'de_DE' => array(
185:             'German',
186:             'Germany',
187:             'ISO8859-1',
188:             'de',
189:             'de'
190:         ),
191:         'el_GR' => array(
192:             'Greek',
193:             'Greece',
194:             'ISO8859-7',
195:             'el',
196:             'en'
197:         ),
198:         'en_GB' => array(
199:             'English',
200:             'Great Britain',
201:             'ISO8859-1',
202:             'en-gb',
203:             'en'
204:         ),
205:         'en_US' => array(
206:             'English',
207:             'United States',
208:             'ISO8859-1',
209:             'en',
210:             'en'
211:         ),
212:         'es_ES' => array(
213:             'Spanish',
214:             'Spain',
215:             'ISO8859-1',
216:             'es',
217:             'es'
218:         ),
219:         'fi_FI' => array(
220:             'Finnish',
221:             'Finland',
222:             'ISO8859-1',
223:             'fi',
224:             'en'
225:         ),
226:         'fr_BE' => array(
227:             'French',
228:             'Belgium',
229:             'ISO8859-1',
230:             'fr-be',
231:             'fr'
232:         ),
233:         'fr_CA' => array(
234:             'French',
235:             'Canada',
236:             'ISO8859-1',
237:             'fr-ca',
238:             'fr'
239:         ),
240:         'fr_FR' => array(
241:             'French',
242:             'France',
243:             'ISO8859-1',
244:             'fr',
245:             'fr'
246:         ),
247:         'fr_CH' => array(
248:             'French',
249:             'Switzerland',
250:             'ISO8859-1',
251:             'fr-ch',
252:             'fr'
253:         ),
254:         'hr_HR' => array(
255:             'Croatian',
256:             'Croatia',
257:             'ISO8859-2',
258:             'hr',
259:             'en'
260:         ),
261:         'hu_HU' => array(
262:             'Hungarian',
263:             'Hungary',
264:             'ISO8859-2',
265:             'hu',
266:             'hu'
267:         ),
268:         'is_IS' => array(
269:             'Icelandic',
270:             'Iceland',
271:             'ISO8859-1',
272:             'is',
273:             'en'
274:         ),
275:         'it_IT' => array(
276:             'Italian',
277:             'Italy',
278:             'ISO8859-1',
279:             'it',
280:             'it'
281:         ),
282:         'iw_IL' => array(
283:             'Hebrew',
284:             'Israel',
285:             'ISO8859-8',
286:             'he',
287:             'he'
288:         ),
289:         'nl_BE' => array(
290:             'Dutch',
291:             'Belgium',
292:             'ISO8859-1',
293:             'nl-be',
294:             'nl'
295:         ),
296:         'nl_NL' => array(
297:             'Dutch',
298:             'Netherlands',
299:             'ISO8859-1',
300:             'nl',
301:             'nl'
302:         ),
303:         'no_NO' => array(
304:             'Norwegian',
305:             'Norway',
306:             'ISO8859-1',
307:             'no',
308:             'en'
309:         ),
310:         'pl_PL' => array(
311:             'Polish',
312:             'Poland',
313:             'ISO8859-2',
314:             'pl',
315:             'en'
316:         ),
317:         'pt_BR' => array(
318:             'Brazillian',
319:             'Brazil',
320:             'ISO8859-1',
321:             'pt-br',
322:             'br'
323:         ),
324:         'pt_PT' => array(
325:             'Portuguese',
326:             'Portugal',
327:             'ISO8859-1',
328:             'pt',
329:             'en'
330:         ),
331:         'ro_RO' => array(
332:             'Romanian',
333:             'Romania',
334:             'ISO8859-2',
335:             'ro',
336:             'en'
337:         ),
338:         'ru_RU' => array(
339:             'Russian',
340:             'Russia',
341:             'ISO8859-5',
342:             'ru',
343:             'ru'
344:         ),
345:         'sh_SP' => array(
346:             'Serbian Latin',
347:             'Yugoslavia',
348:             'ISO8859-2',
349:             'sr',
350:             'en'
351:         ),
352:         'sl_SI' => array(
353:             'Slovene',
354:             'Slovenia',
355:             'ISO8859-2',
356:             'sl',
357:             'en'
358:         ),
359:         'sk_SK' => array(
360:             'Slovak',
361:             'Slovakia',
362:             'ISO8859-2',
363:             'sk',
364:             'en'
365:         ),
366:         'sq_AL' => array(
367:             'Albanian',
368:             'Albania',
369:             'ISO8859-1',
370:             'sq',
371:             'en'
372:         ),
373:         'sr_SP' => array(
374:             'Serbian Cyrillic',
375:             'Yugoslavia',
376:             'ISO8859-5',
377:             'sr-cy',
378:             'en'
379:         ),
380:         'sv_SE' => array(
381:             'Swedish',
382:             'Sweden',
383:             'ISO8859-1',
384:             'sv',
385:             'se'
386:         ),
387:         'tr_TR' => array(
388:             'Turkisch',
389:             'Turkey',
390:             'ISO8859-9',
391:             'tr',
392:             'tr'
393:         )
394:     );
395: 
396:     return $aLanguages;
397: }
398: 
399: /**
400:  * Now the function supports formated strings like %s.
401:  * e.g. echo mi18n("May the %s be with %s", 'force', 'you');
402:  * will output: May the force be with you
403:  *
404:  * @param string $key the string to translate
405:  * @return string the translated string
406:  */
407: function mi18n($key) {
408: 
409:     // skip empty keys
410:     if (0 === strlen(trim($key))) {
411:         return 'No module translation ID specified.';
412:     }
413: 
414:     // dont workd by setup/upgrade
415:     cInclude('classes', 'contenido/class.module.php');
416:     cInclude('classes', 'module/class.module.filetranslation.php');
417: 
418:     // get all translations of current module
419:     $cCurrentModule = cRegistry::getCurrentModuleId();
420:     $contenidoTranslateFromFile = new cModuleFileTranslation($cCurrentModule, true);
421:     $translations = $contenidoTranslateFromFile->getLangArray();
422: 
423:     $translation = $translations[$key];
424: 
425:     // consider key as untranslated if translation has length 0
426:     // Don't trim translation, so that a string can be translated as ' '!
427:     if (0 === strlen($translation)) {
428:         $translation = 'Module translation not found: ' . $key;
429:     }
430: 
431:     // call sprintf on translation with additional params
432:     if (1 < func_num_args()) {
433:         $arrArgs = func_get_args();
434:         $arrArgs[0] = $translation;
435:         $translation = call_user_func_array('sprintf', $arrArgs);
436:     }
437: 
438:     return trim($translation);
439: }
440: 
441: ?>
CMS CONTENIDO 4.9.5 API documentation generated by ApiGen 2.8.0