ericnembot / google-api-translate-java

Automatically exported from code.google.com/p/google-api-translate-java
0 stars 0 forks source link

How to change translate result encoding? #103

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1. I try to translate from english to polish
2. Result is encoded in Cp1250 (polish characters "ąęśćńżół")
3. I would like to get result encoded in UTF-8, how to do it?

I'm uing version 0.92 on Windows Vista.

I try to change system property:
System.setProperty("file.encoding", "UTF-8");
but it didn't help.

Original issue reported on code.google.com by tomasz.l...@gmail.com on 28 Sep 2010 at 12:21

GoogleCodeExporter commented 8 years ago
hello ... 
have u managed to do it ?

I have the same problem in translatin from russian ... with cyrillic characters.
i managed to bypass that by setting my reading document from unicode to utf8 
before running and then setting it back to unicode.

i have found here 
http://stackoverflow.com/questions/361975/setting-the-default-java-character-enc
oding  that one should initialize the vm character encode before running 
anything. but that still didn't work ... 
i have also read that one can set "User-Defined File Attributes" but i have yet 
to test that.

if you have done it please post it so I may take a crack at it.  thank you.

Original comment by AnDrei...@gmail.com on 28 Oct 2010 at 6:56

GoogleCodeExporter commented 8 years ago
This is down to your operating system or perhaps the application using the jar, 
for example maybe your IDE. It's not an issue with the library itself. I'm not 
a Windows user so I can't offer any further info. Closing.

Original comment by rich.mid...@gmail.com on 6 Nov 2010 at 4:53

GoogleCodeExporter commented 8 years ago
I resolve it in the following way:
...
FileOutputStream fos = new FileOutputStream(file.getCanonicalFile());
Writer  writer = new OutputStreamWriter(fos, "UTF-8");
writer.write(contents);
writer.close();
...

where contents is a string translated using Google API Translate.

Using this template you can write in each encoding supported by your JRE/JDK.

Original comment by tomasz.l...@gmail.com on 7 Nov 2010 at 7:34