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