Unable to translate in javascript in Drupal 7 - javascript

I am using jQuery Validation plugin in a Drupal based website and it is working fine. Problem is I can't translate custom error message from .po file. I tried to using Drupal.t() function but no luck. When I use this function in console.log(), it gives me original message which is written in English but I want it should be translated in other language. Could someone tell me how to translate string from .po file to javascript. What I did as:
In Js file:
console.log(Drupal.t('Invalid Email Address.'));
In .po:
msgid "Invalid Email Address."
msgstr "ইমেইলটি সঠিক নয়"
Result: Invalid Email Address..
My Drupal version is 7.

First of all check string existence in "Translate" tab of "Translate interface" section (/admin/config/regional/translate/translate)
If string exists, try to reimport your .po file through "Import" tab (/admin/config/regional/translate/import). Perhaps, You will need to use potx module to create valid .pot and .po files

Related

How to access full email source code in thunderbird message_display_action extension?

I am building an extension in Thunderbird with UI element message_display_action for my school project. I am wondering if I can access full email source code from java script file that I am using for building up my html page when pressing on button my extension. I found a funciton named getFull(messageId) in documentation at https://webextension-api.thunderbird.net/ but I don't understand how to use that function and I don't even know what messageId is. I know it is a integer but I don't know how to get that integer for a specific email. I entered permission (messagesRead) in my manifest file of extension for reading emails but i still don't know how to use that function. I didn't find any examples or tutorials on the internet so if anyone can help me or atleast point me to the right direction.
Getting the id of the currently displayed message
You should take a look at https://github.com/thundernest/sample-extensions/tree/master/messageDisplay, which is an example how to get the id of the currently displayed message from the messageDisplayAction using messageDisplay.getDisplayedMessage().
See also https://webextension-api.thunderbird.net/en/latest/messageDisplay.html.
messages.getFull()
Didn't find a small example using that API. As a hint you should note that this function works on the different MIME parts a mail consists of.
You will not get the complete source of the email that way. To get the raw source you would need to use messages.getRaw(). But you should probably not use getRaw() unless you really need it, because you would need to handle the complete parsing of the message yourself.

this.importTextData returns undefined

I am trying to import data from a tab delimited text file into a PDF using javascript. I am attempting to do this (testing just the first line, at least) through the JavaScript Console using the following code:
var blah = this.importTextData("/C/Users/sbarry/Desktop/abc123.txt", 0)
console.println(blah)
My text file looks like this:
First Second
ABC 123
DEF 456
GHI 789
I made sure I had form fields labeled First and Second on my PDF and then executed my code. The result is:
undefined
It runs successfully.
Under my preferences I have the checkbox "Enable JavaScript Actions" checked, and I have "Enable Safe Reading Mode" unchecked in order to overcome any security restrictions. How can I make this work?
I am using Foxit PhantomPDF ver. 7.2.
UPDATE:
I got a response from someone at the Foxit team. Apparently their software recognized the function but is unable to implement it, so hopefully that will be addressed in the near future. For now, I am going to be using this.importAnFDF by generating an FDF file from scratch. (NOTE: This function does not have a return value, unlike this.importTextData.)
For information on FDF file structure, see section 12.7.7 of this document:
http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf
The easiest way to see what an FDF file requires is to export one from your PDF editing software, open it with notepad or something similar and edit the field names and values to whatever is appropriate for your PDF form.

How to apply a localization to a javascript string

I assigned a string to a javascript string object, such like :
var word = "Please input correct verb"
I want this string be in control by resource file in asp.net project. Does it provide the function to replace the string using a ASP.NET syntax to switch languages?
<%$ Resources:Registration, correctverb%>
Thanks.
There are various l18n projects for JavaScript, e.g. http://i18next.com/
If you have ResX files in your ASP project and you want them as JavaScript or JSON files you can convert them here; or via the REST API you could convert a resource file as follows:
$ curl --data-binary #messages.resx \
http://localise.biz/api/convert/resx/messages.json
(example in cURL, which I guess you may not have if you're on Windows)
A common approach for this is creating an HTTP handler that evaluates requests for say files with the extension *.js.axd (or whatever extension you come up with) and then parse the javascript file by replacing defined tokens with the actual localized resource value.
It may be costly only the first time the file is requested but then everything should run smoothly if caching is applied. Here's an example of how to create a handler, parsing the file should be trivial. You could use the same syntax to define localized strings on your file: <% LocalizedResourceName %>

Please explain me what this javascript code does

I have a javascript with the following code:
caburl="http://"+top.window.location.host+"/ims.cab";
cabver="1,1,1,5";
document.write("<object id='IMS' width=0 height=0 classid='CLSID:8246AC2B-4733-4964-A744-4BE60C6731D4' codebase='"+caburl+"#version="+cabver+"' style='display:none'></object>");
From the above lines, I can understand that the first line specifies the location of cab file. Second Line specifies the cab file version.
Can anyone please explain me, what the third line does..which starts with Document.Write....
I dont have any knowledge of Javascript and want to convert the task performed by this javascript into my exe file.
Expecting a quick and positive response.
The third line writes the generated string value to the page (concatenating strings with the values of the caburl and cabver variables).
This adds an object element to the page with the values in the string.
From the value classid and the use of cab in the variable names, I would deduce this is an ActiveX component (so would only work on IE). This is normally used for installing the component on the client computer.
It joins a string together to make an html tag, and then using document.write appends it to the HTML document.
The third line writes the string enclosed inside the write() function into the document being displayed in the browser.
Note that because of the style='display:none' text in the string , the <object> won't be visible in the browser.
The code will install Java CAB file called "ims.cab" hosted on some server. See this question as well for reference: extract cab file and execute the exe file(inside the cab file) automatically
To do this with EXE of your own, you can take a look here: http://www.codeproject.com/KB/files/CABCompressExtract.aspx
Let us know what language you intend to use (C++, C# etc) for further help.

IntelliJ: how to force editor to treat a file as javascript?

I'm creating a Grails app in IntelliJ 10 and have a javascript file that is created dynamically, as a Grails view.
For that reason the javascript file doesn't end in '.js'. It ends in '.gsp' because it's a Groovy Server Page that spits out javascript.
IntelliJ doesn't know it's a javascript file so it doesn't give me code completion or warnings.
I want my code complete and syntax checking! Is there a way to force IntelliJ to treat this specific file as Javascript, WITHOUT messing up the IntelliJ's correct treatment of .gsp files everywhere else?
Thanks!
The above answer is slightly outdated. You can do the same in IntelliJ 14 by doing the following:
Go to Preferences (Mac OSX : Cmd + Comma)
Under Editor -> File Types
In the Recognized File Types Highlight JavaScript files (JavaScript)
Under Registered Patterns press the + button
Enter your regex pattern (for example: *.js.scala.html) and press OK
Cheers!
You can add additional extensions to the JavaScript in Settings (Preferences on Mac) | File Types.
See also Settings | Template Data Languages where you can configure certain files in the project as templates producing specified language to get proper code completion.

Categories