From d4fb239130d3ba1de1457d0dcb3e05360c85f4de Mon Sep 17 00:00:00 2001 From: Neil Blakey-Milner Date: Mon, 5 Dec 2005 16:56:11 +0000 Subject: [PATCH] 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. --- lib/i18n/i18n.inc.php | 21 +++++++++++++++++++++ lib/i18n/i18nregistry.inc.php | 39 +++++++++++++++++++++++++++++++++++++++ lib/i18n/i18nutil.inc.php | 6 ++++++ 3 files changed, 66 insertions(+), 0 deletions(-) create mode 100644 lib/i18n/i18n.inc.php create mode 100644 lib/i18n/i18nregistry.inc.php create mode 100644 lib/i18n/i18nutil.inc.php diff --git a/lib/i18n/i18n.inc.php b/lib/i18n/i18n.inc.php new file mode 100644 index 0000000..3bf8f22 --- /dev/null +++ b/lib/i18n/i18n.inc.php @@ -0,0 +1,21 @@ +sDomain = $sDomain; + $this->sPath = $sPath; + } + + function gettext($sContents) { + return dcgettext($this->sDomain, $sContents, LC_MESSAGES); + } +} + +class KTi18nGeneric { + function KTi18n() { + } + + function gettext($sContents) { + return $sContents; + } +} diff --git a/lib/i18n/i18nregistry.inc.php b/lib/i18n/i18nregistry.inc.php new file mode 100644 index 0000000..c053a4a --- /dev/null +++ b/lib/i18n/i18nregistry.inc.php @@ -0,0 +1,39 @@ +_ai18nDetails[$sDomain] = array($sDomain, $sDirectory); + bindtextdomain($sDomain, $sDirectory); + bind_textdomain_codeset($sDomain, 'UTF-8'); + } + + function &geti18n($sDomain) { + $oi18n =& KTUtil::arrayGet($this->_ai18ns, $sDomain); + if (!empty($oi18n)) { + return $oi18n; + } + $aDetails = KTUtil::arrayGet($this->_ai18nDetails, $sDomain); + if (empty($aDetails)) { + return new KTi18nGeneric; + } + $oi18n =& new KTi18n($sDomain, $sDirectory); + $this->ai18ns[$sDomain] =& $oi18n; + return $oi18n; + } +} + diff --git a/lib/i18n/i18nutil.inc.php b/lib/i18n/i18nutil.inc.php new file mode 100644 index 0000000..873009d --- /dev/null +++ b/lib/i18n/i18nutil.inc.php @@ -0,0 +1,6 @@ +