Commit d4fb239130d3ba1de1457d0dcb3e05360c85f4de
1 parent
943aba1d
Add an i18n infrastructure that allows for multiple different domains to
receive translations from. This allows for plugins to bind an i18n domain name to their translations, allowing for plugins to be shipped with their own gettext po/mo files and be displayed with the most appropriate translation. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4331 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
66 additions
and
0 deletions
lib/i18n/i18n.inc.php
0 โ 100644
| 1 | +<? | |
| 2 | + | |
| 3 | +class KTi18n { | |
| 4 | + function KTi18n($sDomain, $sPath) { | |
| 5 | + $this->sDomain = $sDomain; | |
| 6 | + $this->sPath = $sPath; | |
| 7 | + } | |
| 8 | + | |
| 9 | + function gettext($sContents) { | |
| 10 | + return dcgettext($this->sDomain, $sContents, LC_MESSAGES); | |
| 11 | + } | |
| 12 | +} | |
| 13 | + | |
| 14 | +class KTi18nGeneric { | |
| 15 | + function KTi18n() { | |
| 16 | + } | |
| 17 | + | |
| 18 | + function gettext($sContents) { | |
| 19 | + return $sContents; | |
| 20 | + } | |
| 21 | +} | ... | ... |
lib/i18n/i18nregistry.inc.php
0 โ 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once(KT_LIB_DIR . '/i18n/i18n.inc.php'); | |
| 4 | + | |
| 5 | +class KTi18nRegistry { | |
| 6 | + var $_ai18nDetails = array(); | |
| 7 | + var $_ai18ns = array(); | |
| 8 | + | |
| 9 | + function &getSingleton() { | |
| 10 | + if (!KTUtil::arrayGet($GLOBALS, 'oKTi18nRegistry')) { | |
| 11 | + $GLOBALS['oKTi18nRegistry'] = new KTi18nRegistry; | |
| 12 | + } | |
| 13 | + return $GLOBALS['oKTi18nRegistry']; | |
| 14 | + } | |
| 15 | + | |
| 16 | + function registeri18n($sDomain, $sDirectory = "") { | |
| 17 | + if (empty($sDirectory)) { | |
| 18 | + $sDirectory = KT_DIR . '/i18n'; | |
| 19 | + } | |
| 20 | + $this->_ai18nDetails[$sDomain] = array($sDomain, $sDirectory); | |
| 21 | + bindtextdomain($sDomain, $sDirectory); | |
| 22 | + bind_textdomain_codeset($sDomain, 'UTF-8'); | |
| 23 | + } | |
| 24 | + | |
| 25 | + function &geti18n($sDomain) { | |
| 26 | + $oi18n =& KTUtil::arrayGet($this->_ai18ns, $sDomain); | |
| 27 | + if (!empty($oi18n)) { | |
| 28 | + return $oi18n; | |
| 29 | + } | |
| 30 | + $aDetails = KTUtil::arrayGet($this->_ai18nDetails, $sDomain); | |
| 31 | + if (empty($aDetails)) { | |
| 32 | + return new KTi18nGeneric; | |
| 33 | + } | |
| 34 | + $oi18n =& new KTi18n($sDomain, $sDirectory); | |
| 35 | + $this->ai18ns[$sDomain] =& $oi18n; | |
| 36 | + return $oi18n; | |
| 37 | + } | |
| 38 | +} | |
| 39 | + | ... | ... |