Joomla插件汉化小程序

这两天在搞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的插件的人员有点帮助吧

posted @ 2014-06-20 17:09  lvyahui  阅读(414)  评论(0编辑  收藏  举报