Skip to content
Snippets Groups Projects
Commit 979b4a1e authored by lobo's avatar lobo
Browse files

Merge pull request #1255 from mlutfy/4.3-crm12446

CRM-12446 : support for extension translation (with native gettext only, for now)
parents d10fb7b0 1a3cba0e
No related branches found
No related tags found
No related merge requests found
......@@ -229,6 +229,14 @@ class CRM_Core_I18n {
$context = NULL;
}
// gettext domain for extensions
$domain_changed = FALSE;
if (isset($params['domain'])) {
if ($this->setGettextDomain($params['domain'])) {
$domain_changed = TRUE;
}
}
// do all wildcard translations first
$config = CRM_Core_Config::singleton();
$stringTable = CRM_Utils_Array::value($config->lcMessages,
......@@ -303,6 +311,10 @@ class CRM_Core_I18n {
$text = addcslashes($text, "'");
}
if ($domain_changed) {
$this->setGettextDomain('civicrm');
}
return $text;
}
......@@ -361,6 +373,41 @@ class CRM_Core_I18n {
}
}
/**
* Binds a gettext domain, wrapper over bindtextdomain().
*
* @param $key Key of the extension (can be 'civicrm', or 'org.example.foo').
*
* @return void
*/
function setGettextDomain($key) {
static $cache = array();
// It's only necessary to find once
if (! isset($cache[$key])) {
$config = CRM_Core_Config::singleton();
try {
$mapper = CRM_Extension_System::singleton()->getMapper();
$path = $mapper->keyToBasePath($key);
$info = $mapper->keyToInfo($key);
$domain = $info->file;
bindtextdomain($domain, $path . DIRECTORY_SEPARATOR . 'l10n');
bind_textdomain_codeset($domain, 'UTF-8');
$cache[$key] = $domain;
}
catch (CRM_Extension_Exception $e) {
// There's not much we can do at this point
$cache[$key] = FALSE;
}
}
if (isset($cache[$key]) && $cache[$key]) {
textdomain($cache[$key]);
}
}
/**
* Static instance provider - return the instance for the current locale.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment