|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Bruno Ghisi's Blog
MessagePropertyGenerator: a java util class for translating message bundlesPosted by brunogh on May 19, 2009 at 06:28 PM | Permalink | Comments (2)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 |
May 2009
Search this blog:CategoriesCommunity: Java CommunicationsCommunity: Java Enterprise Community: Java Tools Community: Java User Groups Community: JavaDesktop Community: Mobile & Embedded Community: NetBeans J2EE J2SE JavaOne Mobility Open Source Tools Archives
May 2009 Recent EntriesMessagePropertyGenerator: a java util class for translating message bundles Sun has fixed SBDTV Forum's messy with the new Java DTV specification Simple Book Borrowing using Grails Articlesj1-2k8-mtW09: Marge: Java Bluetooth Framework | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
|