這兩天在搞joomla插件,在看peter的視頻,在此謝過他了。看到它漢化插件那個視頻。反正閒着無聊,就寫了一個Java小程序,方便使用joomla的人漢化插件。這個程序的方法很簡單,你只要先運行outputToFile方法,將原來的英文配置拷貝到控制檯,在輸入ok,程序就會將英文配置輸出到兩個文件,你將zhi.txt中的英文利用百度翻譯或者google翻譯翻譯好,覆蓋zhi.txt中的內容,然後再運行getTranslationResult方法,將翻譯好的重組一下重新輸出至控制檯。沒花多少時間,所以代碼寫的也很差,各位不要罵人丟磚啊。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
* 將joomla插件漢化
* @author Agrin
*
*/
public class JoomlaPlugIn {
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
/*
* 方法
*
* 在控制檯輸入英文配置 字段=“值”
*
* 從文件1當中逐行讀取,拆分成字段 和 值,分別輸出到兩個文件中,ziduan.txt 和 zhi.txt中
*
* 將值當中的內容翻譯好
*
* 然後再從兩個文件中讀數據,然後拼湊在一塊,輸出到控制檯中
*
*/
File fieldFile = new File("ziduan.txt");
File valueFile = new File("zhi.txt");
if(!fieldFile.exists() || !valueFile.exists()){
return;
}
// outputToFile(fieldFile, valueFile);
getTranslationResult(fieldFile, valueFile);
}
/**
* 從文件中讀取出翻譯好的中文,拼湊好打印到控制檯
* @param fieldFile
* @param valueFile
* @throws FileNotFoundException
* @throws IOException
*/
public static void getTranslationResult(File fieldFile, File valueFile)
throws FileNotFoundException, IOException {
BufferedReader fieldBr = new BufferedReader(new FileReader(fieldFile));
BufferedReader valueBr = new BufferedReader(new FileReader(valueFile));
StringBuilder sb = new StringBuilder();
String field = fieldBr.readLine();
String value = valueBr.readLine();
while (field != null && value != null) {
value = value.replaceAll("“", "");
value = value.replaceAll("”", "");
sb.append(field+" = "+"\""+value+"\""+LINE_SEPARATOR);
field = fieldBr.readLine();
value = valueBr.readLine();
}
System.out.println();
System.out.println(sb.toString());
}
/**
* 將英文配置輸出到文件
* @param fieldFile
* @param valueFile
* @throws IOException
*/
public static void outputToFile(File fieldFile, File valueFile)
throws IOException {
BufferedReader confBr = new BufferedReader(new InputStreamReader(System.in));
PrintWriter fieldPt = new PrintWriter(new FileWriter(fieldFile),true);
PrintWriter valuePt = new PrintWriter(new FileWriter(valueFile),true);
String input = null;
while(!"ok".equals(input = confBr.readLine())){
String records[] = input.split("=");
fieldPt.println(records[0]);
valuePt.println(records[1]);
}
fieldPt.close();
valuePt.close();
}
}
這是翻譯好的中文
希望對漢化joomla的插件的人員有點幫助吧