Overview

Packages

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