Translate English to some other Language in RAD or Eclipse - java

I have written comments in English in my Java files but now my client wants it in Spanish, So is there any tool/Plugin available in RAD or ECLIPSE IDE to convert all the comments in other language. I am using google translator to convert comments manually.

I'm not aware of any plugin like that. First, I would make sure the client really really wants this. Doing an automatic translate of highly technical text will not give a very good quality. I question if they will be usable at all, do a test translate of a couple of comments first to get approval.
If they really want something that is usable someone with language and technical skill would have to manually translate everything, which would take time/money.
But, if I had to do it, I would take the idea from this answer to automatically launch a web browser from Eclipse, and use the URL to google translate, https://translate.google.se/#en/es/${selected_text}, should work.
If the codebase is large and the comments can be easily found, such as a javadoc, I would write some script to automatically handle this. Google translate has an API you can use. See REST API doc

Every now and then a developer has to work on a code base that is in a language that is unknown to him. In this case, he would need to copy variable, class, method names to Google Translate to see what they actually mean.
The Source Code Translation in Eclipse tries to help such developers, by providing a popup with the translated words, when hovering the mouse over them. The plugin is able to handle compound words or phrases that use camelCase or underscore "_" as separation methods.
For the plugin to work, a properties file containing the word to be translated, and the translation needs to be created and added from the Preferences section of the plugin.
Add this URL to your Eclipse Installation to reach this solution's update site.
https://github.com/Testehan/TranslationPluginInstall/raw/master

In External Tools Configurations
Location : ${system_path:cmd.exe}
Arguments : /C start "" "https://translate.google.com/#en/fr/${selected_text}"

Related

Escaping HTML characters in JSP without special library

I'm a new programmer at a software house, and let's just say I can't make too much modification that includes a major changes, for example like adding library. In the current project, we're using JSP and Servlet, and some other advanced GUI that I never knew (they said it's a derivative of Eclipse, called Enfinity). The Enfinity also hides the libraries under obscure locations, and it's very different than in Java. So I don't think I will able to understand about the library location too, moreover adding some new library.
The problem here, I need to escape HTML characters like &, <, >, ", and ', but when I search solution on the internet, usually the solution involves using JSTL ( c:out or ${fn:escapeXML} ) or importing a library (Spring's HTMLEscape, or Apache's StringEscapeUtils). JQuery, on the other hand, is imported, but sadly, not related to solution. But the problem is JSTL is not part of the library readily imported into the project. Java, JSP, and Servlet are kinda new to me, as I didn't get Java at all in my college, so I don't know either what library is standard in JSP (already present, without I have to add it physically). I don't even know whether the Apache's StringEscapeUtils is present or not. Do you have any suggestion / codes on how I should escape the HTML characters under my circumstances? Thank you very much.
If your target platform is really Enfinity - as you are stating in your questions and in the tags - you should be using the Enfinity constructs even though this is not completely what you know from JSP. Please allow me to reopen this old thread and try to help you with that.
Enfinity got an own "templating language" called ISML. In the end ISML is precompiled to JSP. You can find a documentation with any installation of the Enfinity application server (a PDF called enfsuite_dev_programming). You should ask your project manager or build engineer if you don't have it available.
On the other hand I read from your statement that you possibly have the Enfinity Studio available (which is the IDE of Enfinity - a derivate of Eclipse. You should be able to access the developer guide through Enfinity Studios Help Menu. This menu may have some errors in some versions of the Studio unfortunately. However, you can get there through Window > Show View > Other > Help. On bottom of the help window is a "Content" link that will take you to the overview. The developer guide is under the table of contents link Enfinity Suite Application Programming Guide.
However you get to the guide: in the appendix you find a section "Reference > ISML Tags / ISML Functions / ISML Modules". Browsing through it you will find the function:
<isprint value="#value#" encoding="on|off">
Encoding is "on" by default and this statement will do exactly what you need: it will encode all HTML special characters in #value#. The special here is that the key value matches to an object in the so called Pipeline Dictionary which is a construct storing objects coming out of the Enfinity business logic workflow layer (so called pipelines).
This pipeline dictionary can be manipulated in JSP using:
Map<String, Object> pdict = getPipelineDictionary();
The dictionary is a standard java Map and can be manipulated using the known operations. However, the preferred way would be using pipelines or at least the respective ISML tag
<isset name="name" value="#value#" scope="request|session">
A full example for usage with JSP/ISML would be:
<%
String myString = "<b>Test</b>";
getPipelineDictionary().put("myDictKey", myString);
%>
<isprint value="#myDictKey#">
You can import org.apache.commons.lang.StringEscapeUtils and add its jar file. That are not by default present in jsp/servlets. It will provide you facility to escape characters from html, mysql, xml etc. Also you can make your own method to check for the character sequence and then use it as a escape function to escape data you want.

Using Clear parser for semantic role labeling

I want to use the Clear Parser for extract semantic role label of the input sentence. I downloaded the jar file here but I don't know how to use this jar file.
I search on the web but there isn't good guideline for using it.
Please help me to solve this problem (My project is in eclipse on windows).
Mind that Clearparser is now ClearNLP. For an idea how to use the ClearNLP API, check out the DemoNLPDecoder linked from their project page. In fact, that's a small runnable application to which you pass all the models as command line arguments, along with an input and a output file.

C++ or Java Library for automated code editing?

I am writing/planning to write a program that takes in a java file (or multiple java files), and edits and adds functions/classes/variables and then outputs a new java file (or multiple files).
Is there a C++ or Java library that
Can recognize and output names of classes/functions within a text file
Can recognize and output the names of the input arguments for said classes/functions
Can allow me to insert code at specific lines or within specific functions
Can search for a given variable name/value
Maintains original file formatting
I would prefer not having to manually code something to do the above, so any help would be appreciated.
Thank you in advance!
EDIT: I currently use Eclipse, and am unsure of how to proceed. So to further explain my question:
In eclipse, if I write a program that opens another .java file, How would I go about 'asking' eclipse to output, say, all the class names of the .java file I just opened?
Also I will explain the 'purpose' of this project to further clarify. I want to write a program that can take in any java file, and turn it into a class that can implemented remotely via RMI. To do this I will need to add an execute() function, have the file implement Task and Serializable and add a few variables, etc... Based on my knowledge, doing this in Eclipse would require manual editing of the program, but I would like to completely automate this process.
Thank you, again.
Much of what you need can be found in a modern IDE; and some very good IDEs are open source (eclipse and Intellij IDEA Community Edition for Java). You might look there to see if there are modules that suite your needs.
Looks like you are talking of a tool like eclipse. You might not be looking for a full fledged IDE, but the requirements that you have mentioned are fulfilled by any basic IDE.
If you wish to make one of your own, you can do that using eclipse rich client platform.
All that you would need from Java is the reflection API.

Java phonetics or language pronounciation

I am currently making a project for school, where I am going to make a program which teaches children how to read. My basic idea for the program was produce the sentence and then get Windows Anna to say it. My question to you is, how can I access Winodws Anna through Java? and is there a better way of doing this?
Thanks
If having the program access internet is acceptable, then you could use iSpeech.
You can use their API, but the problem with that is that it is limited to 200 uses/day.
iSpeech has decently sounding voices, generally more polished than other TTS engines I've tired like espeak or FreeTTS, because it actually pronounces the words more fluently. Sure, it might pronounce 'Wind', relating with air, as 'Wind', relating to twisting, but other than that, it speaks quite well.
Also, while I haven't had any prior experience with this, I found an article that shows you how to access the MS Speech with command line (which can obviously be commanded through Java[if you do not know how, here is a good article]). It is located here. In command line, all you do is type in 'SayDynamic.exe* the text you want to speak".
*Or SayStatic, the other download available on the page.
This method seems to be better in terms of speed and not relying on internet access, but it definitely does NOT pronounce things as well as iSpeech. I guess the ideal thing for your program to have would be to use iSpeech when online, and use the Say*.exe when offline.
The site also provides the source code of the program. As you might notice, it is NOT Microsoft Anna's voice, but you can specify that in the source and recompile it.
Hope I helped!
You can use command line utiity NirCmd that uses text-to-speech API installed on Windows.
So, supply this utility together with your java application and run it with appropriate command line.
You can try FreeTTS : a speech synthesizer written in java.
You can try to call the Microsoft Speech API (SAPI) but I don't know how to do it in java.
Can you tell us how you invoke NirCmd ?
Altenatively to NirCmd, you can build your own tool in C# that will read the text. The text could be within a txt and your tool invoked with the path to that txt as argument. You can easily adapt a demo project like this one : http://www.codeproject.com/Articles/19334/Text-to-Speech-using-Windows-SAPI
There is the Speech platform of Windows
http://www.microsoft.com/en-us/download/details.aspx?id=27226
The Speech runtime
http://www.microsoft.com/en-us/download/details.aspx?id=27225
You can use JNA (not JNI) to interact with dll from java
https://github.com/twall/jna

How to enlarge eclipse java editor functionality using plugins?

Hope somebody could help me, giving a hint and way out.
Right now I'm involved in a ambitious project trying to create mixed math and programming IDE.
After a huge prestudy we decided to use eclipse as a base, and somehow add Mathematica,maple functionality.
Generally speaking we want to make entering math expressions (a = sin(Pi)+10^2) into java code possible. Also those expressions should be showed in LaTex view, right in the code to make it more readable for engineers, to illustrate the code we want to implement insertion images in comments.
As we need all th java editor functionality, in my opinion it's correct to use standart eclipse java editor, and learn it to behave with other objects, e. g. images.
So my questions are:
- Could somebody share experience developing similar products?
- May be there are something like we are going to develop?
Probably I'll write more questions, especially tighter ones.
That is certainly an interesting sounding project. As Gilbert Le Blanc mentions, the Java Editor is highly optimized to edit Java code and is not meant to be extensible.
That being said, I can recommend two options (one that plays by the rules, and one that goes against them).
Instead of embedding your images directly in the Java editor, you could implement your own hover, through the org.eclipse.jdt.ui.JavaEditorTextHovers extension point (so it would work like JavaDoc hovers), or in a separate view that sits beside the editor (so it would work like the JavaDoc view). (This is playing by the rules.)
A while ago, I implemented a prototype editor that allows you to edit Java code with snippets of CAL (a functional JVM language) embedded inside of it. The snippets were stored in there own little window inside the editor. This was a prototype and not everything worked smoothly and it was also using Eclipse 3.2, but this is exactly the kind of thing that you want to do. It won't be easy to compile and run the code, but you can have a look at it....well, maybe. I have to find an EPL variant of the source code. Until then, just realize that hacking the Java Editor like this requires some specialized knowledge about the JDT and you need to be careful about how you do it so that you do inadvertently break other things.
Edit
Here is a zip of the project I described. It will not compile as it is, but you can look at the source code:
Try this link. It should be viewable by the world.
The essential thing to realize is that swt StyledText widgets can themselves contain other widgets. This project leverages that in Java editors.
In particular, look at the class org.openquark.cal.eclipse.embedded.containing.ContainingEditor, which is a sub-class of CompilaitonUnitEditor. This particular class embeds a second text editor (the contained editor) inside of another editor (the containing editor).
Also, take a look at org.openquark.cal.eclipse.embedded.containing.ControlManager. This class manages the different controls inside of a styled text of the containing CompilationUnitEditor.
What this project does is creates a Java-like editor, and allows users to embed editors for another language inside of the Java editor. These editors are actually backed by text in the containing Java editor, but the text is covered by the contained editor.
The contained editors move up and down as text is entered into containing editor. Also, you can use the keyboard to gain/lose focus in a contained editor.
It's been several years since I looked at this code, but if you have any questions, drop me a line or add to this question.
The Eclipse Java Editor is made up of hundreds of Java classes. There's an implicit assumption in those hundreds of Java classes that the editor view is just for code.
In my opinion, you'll find it much easier to develop a Mathematica-type editor for your math images, and leave the Java editor alone. Your engineers can open two editors in Eclipse.
If my comments haven't dissuaded you, here's the Eclipse documentation for Eclipse Helios, otherwise known as Eclipse 3.6
The section you'd start with is called the JDT Plug-in Developer Guide.
The Eclipse web site is responding slowly as I'm typing this. You can also access the Help from inside of Eclipse Helios.
Help -> Help Contents
I know exactly what you can do. First, you can turn-on the unicode character set. This will allow you to have variables such as greeks, which makes the code much more readable. [General->WorkSpace->Text Encoding = UTF-8].
// Apply spring soft constraint using Erin Catto's method with Semi-Implicit Euler :
// Figure out (ω,ζ) from node sizes, then k=mEff.ω², c=2.mEff.ω.ζ
double ω = 2.0*π*f; // ω (angular frequency)
double k = meff * ω*ω; // spring stiffness
double ζ = (b1.ζ + b2.ζ)/2; // Average out the damping coefficients
double d = 2.0 * meff * ω * ζ; // damping coefficient
double γ=h*(d+h*k); // CFM (Constraint Force Mixing)
Second, your suggestion to have a LaTeX formula visible within the code is also the next best thing. I know it's possible because I wrote one 3 years ago, but I can't find the code anywhere. I had posted it on a forum for eclipse plug-ins but it's gone now.
The good news is that I'm writing it again, because I need it - that's how I found your post . This time I'm using jlatexmath which is better than what I used last time.
The idea was/is that you can embed a formula in a comment as LaTeX, and the plug-in renders the LaTeX in a tooltip when you hover on it.
I'll post a link or code here when I'm done. Most of the work is figuring out how to make eclipse accept the new hover control.
J.D.
Ok, as a follow-up to my post above, here is the Eclipse Plug-In Development Environment (PDE) project I developed for this. The Plug-in is named LaTeXHover and will pop-up a tooltip whenever you hover on top of a comment line that contains LaTeX such as:
// $latex i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>$
// $latex x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}$
The LaTeX must be delimited using $latex and $ with no extra spaces.
It uses jlatexmath for rendering.
I'll try to package the plug-in better and add that to the Git repo, and maybe contribute it to one of the Eclipse Plug-In projects. As last time, I don't have time now to do this, but at least it's out there now. Anyone wishing to continue the project from here is welcome to do so.
J.D.
git://github.com/jdbertron/latexhover.git

Categories

Resources