CRM-13580 - Add CRM.translate() helper
authorTim Otten <totten@civicrm.org>
Thu, 1 May 2014 20:54:33 +0000 (13:54 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 1 May 2014 20:54:33 +0000 (13:54 -0700)
js/Common.js
tests/qunit/crm-translate/test.js [new file with mode: 0644]
tests/qunit/crm-translate/test.php [new file with mode: 0644]

index 42d4cafd69b608038ab4b7a888e84e2ee0415ffa..caa981d68d167cc44c8c638873f79f34034bb636 100644 (file)
@@ -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 (file)
index 0000000..44fe01c
--- /dev/null
@@ -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 (file)
index 0000000..db27384
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+CRM_Core_Resources::singleton()->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(...);