Download & Extend

JavaScript Support through Drupal.t()

Project:String Overrides
Version:7.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:chxisawesome

Issue Summary

Just a quick question here, does this module handle translatable strings from js files that use the Drupal.t() function?

I am testing it and it doesn't look like it's replacing it... so I was just looking to clarify this before I throw my computer out the window hehe :)

Thanks!

Comments

#1

Title:Does this module handle Drupal.t() ?» JavaScript Support through Drupal.t()

No it doesn't, but that is definitely a good idea. Would it just send all the strings set in String Overrides to Drupal.locale.strings? How does Locale do it? What if there was an additional String Overrides tab for JavaScript strings?

#2

I opened up locale.module and found this function which looks like it's how its being done: locale_update_js_files().
I then ran a find in files for that function on the whole of drupal, and found _locale_invalidate_js() in locale.inc.

As far as how string overrides should step in I'm afraid it's passed my knowledge... perhaps we should harass someone in #drupal ?

I think having another tab for JavaScript strings would make sense, since this would probably work differently. Again, just guessing here...

Hope this helps -- thanks for caring!

#3

Category:support request» feature request

#4

#5

Status:active» needs work

#6

t() supports locale_custom_strings_en even without Locale enabled -- you can set $custom_strings in settings.php.

Shouldn't Drupal.t() access locale_custom_strings_en too?

#7

Status:needs work» active

Someone must have got this working by now, right?

#8

Version:6.x-1.x-dev» 7.x-1.x-dev
Status:active» needs review

Sue me for abusing the context.

Edit: most of this is, of course, copy-paste from locale.module.

AttachmentSize
stringoverrides_js.patch 1.38 KB

#9

Concerned about having a hash and file IO calculations every page load, what if we were to put the translations directly in Drupal.settings, and then had a stringoverrides.js load them into the Drupal translation system?

Forgive me for not having the .patch file include adding stringoverrides.js itself. I'm lazy.

AttachmentSize
stringoverrides_js_js.patch 1.84 KB
stringoverrides.js 381 bytes

#10

Whoops, should probably be:

(function($) {

/**
* String Overrides behavior to load in JavaScript-based translations.
*/
Drupal.behaviors.stringoverrides = {
  attach: function (context, settings) {
    if (settings.stringoverrides || false) {
      // Make sure the strings array is initialized.
      Drupal.locale.strings = Drupal.locale.strings || {};
      // Add the string overrides translations to the strings array.
      jQuery.extend(Drupal.locale.strings, settings.stringoverrides);
    }
  }
};

})(jQuery);

Needs an actual review though, I haven't tested this thoroughly.

#11

Woot!!!

AttachmentSize
stringjs.patch 1.84 KB
stringoverrides.js_.txt 624 bytes