summaryrefslogtreecommitdiff
path: root/misc/drupal.js
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-11-14 02:17:32 -0500
committerwebchick <webchick@24967.no-reply.drupal.org>2011-11-14 02:17:32 -0500
commitcfc35a0b3e05245e27516631724c668e11ff955d (patch)
treec6720c52c9cc3af3a5eb44e6e187caa8742f0558 /misc/drupal.js
parentf77015e645feb5e805850f24cb988743077724eb (diff)
downloadbrdo-cfc35a0b3e05245e27516631724c668e11ff955d.tar.gz
brdo-cfc35a0b3e05245e27516631724c668e11ff955d.tar.bz2
Issue #488496 by loganfsmyth, Gábor Hojtsy: Implement missing msgctx context in JS translation for feature parity with t().
Diffstat (limited to 'misc/drupal.js')
-rw-r--r--misc/drupal.js24
1 files changed, 17 insertions, 7 deletions
diff --git a/misc/drupal.js b/misc/drupal.js
index 7e2cc4d7b..7ae737c63 100644
--- a/misc/drupal.js
+++ b/misc/drupal.js
@@ -177,13 +177,21 @@ Drupal.formatString = function(str, args) {
* An object of replacements pairs to make after translation. Incidences
* of any key in this array are replaced with the corresponding value.
* See Drupal.formatString().
+ *
+ * @param options
+ * - 'context' (defaults to the empty context): The context the source string
+ * belongs to.
+ *
* @return
* The translated string.
*/
-Drupal.t = function (str, args) {
+Drupal.t = function (str, args, options) {
+ options = options || {};
+ options.context = options.context || '';
+
// Fetch the localized version of the string.
- if (Drupal.locale.strings && Drupal.locale.strings[str]) {
- str = Drupal.locale.strings[str];
+ if (Drupal.locale.strings && Drupal.locale.strings[options.context] && Drupal.locale.strings[options.context][str]) {
+ str = Drupal.locale.strings[options.context][str];
}
if (args) {
@@ -216,25 +224,27 @@ Drupal.t = function (str, args) {
* See Drupal.formatString().
* Note that you do not need to include @count in this array.
* This replacement is done automatically for the plural case.
+ * @param options
+ * The options to pass to the Drupal.t() function.
* @return
* A translated string.
*/
-Drupal.formatPlural = function (count, singular, plural, args) {
+Drupal.formatPlural = function (count, singular, plural, args, options) {
var args = args || {};
args['@count'] = count;
// Determine the index of the plural form.
var index = Drupal.locale.pluralFormula ? Drupal.locale.pluralFormula(args['@count']) : ((args['@count'] == 1) ? 0 : 1);
if (index == 0) {
- return Drupal.t(singular, args);
+ return Drupal.t(singular, args, options);
}
else if (index == 1) {
- return Drupal.t(plural, args);
+ return Drupal.t(plural, args, options);
}
else {
args['@count[' + index + ']'] = args['@count'];
delete args['@count'];
- return Drupal.t(plural.replace('@count', '@count[' + index + ']'), args);
+ return Drupal.t(plural.replace('@count', '@count[' + index + ']'), args, options);
}
};