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
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 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 commentedComment #4
robloachhttp://www.palantir.net/blog/drupals-javascript-translation-system
Comment #5
robloachComment #6
jeffschulert() supports
locale_custom_strings_eneven without Locale enabled -- you can set$custom_stringsin settings.php.Shouldn't
Drupal.t()accesslocale_custom_strings_entoo?Comment #7
aaronbaumanSomeone must have got this working by now, right?
Comment #8
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 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 commentedNew one. With "$output .=" .
Comment #16
robloachVery nice, I wrapped the
$language->languagewith 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 !totalfind in 'media_gallery/colorbox-display.js' to!current of !totalbut 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 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 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 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 commentedpatch in #18 is working great for me
Comment #29
pasqualle#18 works for me
Comment #30
sukh.singh 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 commentedNew patch to remove an "alert" call... "alert(90);"...