From f97524d961d93de77d09ab25d98c6c2e98de9c48 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 1 May 2014 13:54:33 -0700 Subject: [PATCH] CRM-13580 - Add CRM.translate() helper --- js/Common.js | 11 +++++++++++ tests/qunit/crm-translate/test.js | 11 +++++++++++ tests/qunit/crm-translate/test.php | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/qunit/crm-translate/test.js create mode 100644 tests/qunit/crm-translate/test.php diff --git a/js/Common.js b/js/Common.js index 42d4cafd69..caa981d68d 100644 --- a/js/Common.js +++ b/js/Common.js @@ -731,6 +731,17 @@ CRM.validate = CRM.validate || { return dialog.dialog(settings).trigger('crmLoad'); }; + /** eg CRM.translate('org.example.myext', function(ts){ ... }); */ + CRM.translate = function(domain, callback) { + "use strict"; + var altTs = function(message, options) { + options = options || {}; + options.domain = domain; + return ts(message, options); + }; + callback(altTs); + }; + /** * @see https://wiki.civicrm.org/confluence/display/CRMDOC/Notification+Reference */ diff --git a/tests/qunit/crm-translate/test.js b/tests/qunit/crm-translate/test.js new file mode 100644 index 0000000000..44fe01cb04 --- /dev/null +++ b/tests/qunit/crm-translate/test.js @@ -0,0 +1,11 @@ +module('Translation'); + +test('ts()', function() { + equal(ts('One, two, three'), "Un, deux, trois", "We expect translations to work"); +}); + +test('CRM.translate()', function() { + CRM.translate('org.example.foo', function(ts){ + equal(ts('One, two, three'), "Un, deux, trois", "We expect translations to work"); + }); +}); diff --git a/tests/qunit/crm-translate/test.php b/tests/qunit/crm-translate/test.php new file mode 100644 index 0000000000..db27384f1f --- /dev/null +++ b/tests/qunit/crm-translate/test.php @@ -0,0 +1,8 @@ +addSetting(array( + 'strings' => array('One, two, three' => 'Un, deux, trois') + ) +); +// CRM_Core_Resources::singleton()->addScriptFile(...); +// CRM_Core_Resources::singleton()->addStyleFile(...); +// CRM_Core_Resources::singleton()->addSetting(...); -- 2.25.1