Search |
||
MessagePropertyGenerator: a java util class for translating message bundlesPosted by brunogh on May 19, 2009 at 6:28 PM PDT
If you want to translate your message files for a couple of different languages, but you do not have money, do not have time, do not have language specialists friends or do not have anything else to help you, we have a solution... actually we got a "use at your own risk" solution! Here are the steps:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
import java.io.FileInputStream;
public class MessagePropertyGenerator {
private static String baseLanguage = Language.PORTUGESE;
private static String basePropertyFileName = "/home/brunogh/NetBeansProjects/I18NGenerator/src/messages_pt_BR.properties";
private static String enconding = "ISO-8859-1";
private static String fullPathToWriteTargetFiles = "/home/brunogh/NetBeansProjects/I18NGenerator/src/";
private static String[][] targetLanguages = {
{Language.ENGLISH,"messages_en_US.properties"},
{Language.SPANISH,"messages_es.properties"},
{Language.GERMAN, "messages_de.properties"}};
public static void main(String[] args) {
try {
String currentLanguage = null;
String currentFileName = null;
String translatedText = null;
BufferedReader d = null;
for (int i = 0; i < targetLanguages.length; i++) {
d = new BufferedReader(new InputStreamReader(new FileInputStream(basePropertyFileName),enconding));
currentLanguage = targetLanguages[i][0];
currentFileName = targetLanguages[i][1];
String s = "";
StringBuffer sb = new StringBuffer();
Vector
messages_pt_BR.properties
test.helloworld=Olá Mundo!
test.couldihaveabeerplease=Gostaria de uma cerveja, por favor.
test.javarocks=Java é legal!
test.owyes=Sim, {0}, veja isto {1}
Note that you may have problems with large message property files. If is that your case, you can try another solution that does not make a request per line. Anyway, feel free to modify and improve. Have a nice week! Bruno Ghisi»
Related Topics >>
Java Tools Comments
Comments are listed in date ascending order (oldest first)
Submitted by giovanisalvador on Sun, 2009-05-24 06:33.
Very nice tip Bruno. Just as correction, when you say "above" you meant "below", right? :)
|
||
|
|