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