From: Tim Otten Date: Thu, 1 May 2014 20:54:33 +0000 (-0700) Subject: CRM-13580 - Add CRM.translate() helper X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f97524d961d93de77d09ab25d98c6c2e98de9c48;p=civicrm-core.git CRM-13580 - Add CRM.translate() helper --- 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(...);