Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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!
Comment | File | Size | Author |
---|---|---|---|
#31 | stringoverrides-javaScript_support_through_Drupal_t-369658-31.patch | 3.17 KB | Echofive |
#18 | 369658.patch | 2.67 KB | glynnr |
| |||
#16 | 369658.patch | 2.67 KB | RobLoach |
| |||
#15 | stringoverrides-javaScript_support_through_Drupal_t-369658-15.patch | 3.03 KB | Jerenus |
| |||
#13 | stringoverrides-javaScript_support_through_Drupal_t-369658-13.patch | 3.03 KB | Jerenus |
|
Comments
Comment #1
RobLoachNo 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?Comment #2
Manuel Garcia CreditAttribution: Manuel Garcia commentedI 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!
Comment #3
Manuel Garcia CreditAttribution: Manuel Garcia commentedComment #4
RobLoachhttp://www.palantir.net/blog/drupals-javascript-translation-system
Comment #5
RobLoachComment #6
jeffschulert() supports
locale_custom_strings_en
even without Locale enabled -- you can set$custom_strings
in settings.php.Shouldn't
Drupal.t()
accesslocale_custom_strings_en
too?Comment #7
AaronBaumanSomeone must have got this working by now, right?
Comment #8
chx CreditAttribution: chx commentedSue me for abusing the context.
Edit: most of this is, of course, copy-paste from locale.module.
Comment #9
RobLoachConcerned 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.
Comment #10
RobLoachWhoops, should probably be:
Needs an actual review though, I haven't tested this thoroughly.
Comment #11
RobLoachWoot!!!
Comment #12
reszliThere is one small problem with the last patch,
in stringoverrides.js_.txt
should be:
This way it works for me.
Thanks!
Comment #13
Jerenus CreditAttribution: Jerenus commentedHere is final patch about it.
Comment #14
RobLoachVery nice, thanks a lot for the update! Could we get some additional manual testing on this to confirm that it's working? Thanks so much!
Small note before committing, the above should probably be
$output .= '<p>' /* ... */;
Comment #15
Jerenus CreditAttribution: Jerenus commentedNew one. With "$output .=" .
Comment #16
RobLoachVery nice, I wrapped the
$language->language
with an isset check, just to be safe. We'll need a manual terst to make sure this is good, then I think it'd be good to go. Thnaks!Comment #17
thamasApplied the patch from #369658-16: JavaScript Support through Drupal.t() to 7.x-1.8.
Tried to change the string
Item !current of !total
find in 'media_gallery/colorbox-display.js' to!current of !total
but it didn't change anything. Tried it with empty context and context set to 'js'. Caches emptyed of course (also tested in other browser in private mode to avoid browser cache problems).Comment #18
glynnr CreditAttribution: glynnr commentedJust a note to help those that need to get this working:
In the patch above, in this line :
$javascript['settings']['data'][] = array('stringoverrides' => $translations['js']);
The stringoverrides with the context of 'js' are being appended.
Then this line :
jQuery.extend(Drupal.locale.strings, settings.stringoverrides);
Merges them directly into Drupal.locale.strings
However Drupal.t() retrieves the strings like this :
str = Drupal.locale.strings[options.context][str];
Using the key passed in at options.context.
Usually context is not passed in when using Drupal.t() and in these cases it defaults to ''.
So the quick solution here is to ensure that the stringoverrides are merged into the default, by changing
jQuery.extend(Drupal.locale.strings, settings.stringoverrides);
to
jQuery.extend(Drupal.locale.strings[''], settings.stringoverrides);
Then you should find that the stringoverrides identified by the context 'js' will start working.
Attached is the updated patch from #16
Comment #19
A.Kotov CreditAttribution: A.Kotov commentedApplied patch from #18 - see no result.
I have js file attached
and use Drupal.t('bla-bla'); in it.
Should I do something special to make it working?
Comment #20
kevinquillen CreditAttribution: kevinquillen commentedThe patch in #18 only works if you merge the strings into the js context, then specify the context as 'js' in the string override. And you have to add this line, adding the js context into the strings object.
AFTER this change, I was able to override Drupal.t() strings correctly with string overrides, PROVIDED that translated strings are passed in like so:
Comment #21
jrglasgow CreditAttribution: jrglasgow commentedpatch in #18 is working great for me
Comment #29
Pasqualle#18 works for me
Comment #30
sukh.singh CreditAttribution: sukh.singh as a volunteer commented#18 works for me partially, to make it working you will have to do 2 things, which are as follows.
1. Under
admin/config/regional/stringoverrides
, add js under the context column textfield besides the string which is to be changed.2. When I added #18 patch, the stringoverrides.js file copied to the root of the drupal folder. To fix this I have added js folder and moved stringoverrides.js under it in stringoverrides module. I have created a refined patch #30 for the same.
Comment #31
Echofive CreditAttribution: Echofive as a volunteer and commentedNew patch to remove an "alert" call... "alert(90);"...