From: Tim Otten Date: Fri, 11 Oct 2013 17:59:44 +0000 (+0100) Subject: CRM-13580 - ts - Set the default translation domain based on $extensionKey X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d9aa1c6bc28d8a000cb52f66b62b7d7b7ed39955;p=civicrm-core.git CRM-13580 - ts - Set the default translation domain based on $extensionKey Reset $extensionKey when loading each file. This puts the onus on developers to set the extensionKey once in each file using {assign} or {tsScope}, but it prevents the extension key from leaking unintentionally to other files, and it allows developers to handle weird situations explicitly. (Example weird situation -- using one extension to override another extension's template; or having multiple extensions share a common translation key.) ---------------------------------------- * CRM-13580: Set translation domain implicitly in extensions http://issues.civicrm.org/jira/browse/CRM-13580 --- diff --git a/CRM/Core/Smarty.php b/CRM/Core/Smarty.php index a656aa3c70..6422ca2c48 100644 --- a/CRM/Core/Smarty.php +++ b/CRM/Core/Smarty.php @@ -159,6 +159,7 @@ class CRM_Core_Smarty extends Smarty { } $this->register_function('crmURL', array('CRM_Utils_System', 'crmURL')); + $this->load_filter('pre', 'resetExtScope'); } /** diff --git a/CRM/Core/Smarty/plugins/block.ts.php b/CRM/Core/Smarty/plugins/block.ts.php index c0fb5f54be..5d16be9c46 100644 --- a/CRM/Core/Smarty/plugins/block.ts.php +++ b/CRM/Core/Smarty/plugins/block.ts.php @@ -47,6 +47,9 @@ * @return string the string, translated by gettext */ function smarty_block_ts($params, $text, &$smarty) { + if (!isset($params['domain'])) { + $params['domain'] = $smarty->get_template_vars('extensionKey'); + } return ts($text, $params); } diff --git a/CRM/Core/Smarty/plugins/prefilter.resetExtScope.php b/CRM/Core/Smarty/plugins/prefilter.resetExtScope.php new file mode 100644 index 0000000000..01b007009c --- /dev/null +++ b/CRM/Core/Smarty/plugins/prefilter.resetExtScope.php @@ -0,0 +1,12 @@ +