From d9aa1c6bc28d8a000cb52f66b62b7d7b7ed39955 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 11 Oct 2013 18:59:44 +0100 Subject: [PATCH] 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 --- CRM/Core/Smarty.php | 1 + CRM/Core/Smarty/plugins/block.ts.php | 3 +++ CRM/Core/Smarty/plugins/prefilter.resetExtScope.php | 12 ++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 CRM/Core/Smarty/plugins/prefilter.resetExtScope.php 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 @@ +