介绍
java 或前端vue,js 中文查找和替换工具
– 产品多语言开发强力帮忙工具
–目前支持对后缀为".java, .vue, .js文件的查找
目前版本下载地址 中文检查工具v1.3.2.jar
项目地址:
https://gitee.com/linhai-college/chinese-extract-and-replace/
工具图
使用说明
- 运行:条件先安装JDK , 再运行 “中文检查工具v1.X.X.jar”
- 选择一个要分析的目录,可以是 java文件src目录,也可以是前端开发代码根目录。
- 点击“分析”:会提取目录下所有文件里面的中文。分析结果默认 在分析目录下的 checkResult.txt 。也可以另外保存。
- “保存单词”: 会把提取的中文 去重后输出到文件。
- “校验”:检查目录下所有文件里面的中文,是否含有:1、条件判断中有中文字符;2、图片或者资源中有中文字符;3、链接中有中文字符.
- “全部替换”:仅用于前端代码,会在分析目录下的\lang目录下生成多语言文件:zh.js和en.js,将分析目录下所有中文替换为Key。但上面校验未通过的部分不做替换。
- “用key替换”:用“全部替换”生成的中文替换为Key,对查找目录下的中文进行多语言替换。
项目地址
https://gitee.com/linhai-college/chinese-extract-and-replace
目前版本下载地址
https://gitee.com/linhai-college/chinese-extract-and-replace/raw/master/out/%E4%B8%AD%E6%96%87%E6%A3%80%E6%9F%A5%E5%B7%A5%E5%85%B7v1.3.0.jar
源代码
package com.zy.extract;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
public class ExtractUI extends JFrame {
private static final long serialVersionUID = 1L;
private static ExtractUI frame;
private JPanel contentPane;
private JTextField sourcePath;
private JTextField outPath;
private JTextField textIgnore;
private JTextField textkeyFile;
private JLabel lblNewLabel_1;
private JLabel resultMsg;
private JScrollPane scrollPane;
private JTextArea resultArea;
private JButton btnOutPath;
private JButton btnAnalysis;
private JButton btnKeyFile;
private JButton btnSaveResult;
private JButton btnSaveWord;
private JButton btnCheck;
private JButton btnReplace;
private JButton btnKeyReplace;
// 非中文的字符范围
// private static String REG_CN = "[^\u4e00-\u9fa5]";
// 中文的字符范围
private static String REG_CN = "[\u4e00-\u9fa5]";
private static Pattern pattern_cn = Pattern.compile(REG_CN);
// 双引号
private static Pattern pattern_symbol1 = Pattern.compile("\"(.*?)\"");
// 单引号
private static Pattern pattern_symbol2 = Pattern.compile("'(.*?)'");
// ></间
// private static Pattern pattern_symbol3 = Pattern.compile(">(.*?)</");
private static Pattern pattern_symbol3 = Pattern.compile(">\\[^\\]</");
// 提示区信息
private StringBuilder sb = new StringBuilder();
// 检查文件总数
private long allFileNumber = 0;
// 有中文文件数
private long fileNumber = 0;
// 有中文词数
private long wordNumber = 0;
// 有问题中文词数
private long wordProblemNumber = 0;
// 去重后的单词
private Set<String> setWord = new HashSet<String>();
private HashMap<String, String> wordKeys = new HashMap<String, String>();
// 是否分析
private boolean isAnalysis = false;
// 是否校验通过
// private boolean isCheckPass = false;
private List<String> ignoreList = new ArrayList<String>();
/**
* Launch the application.
*/
public static void main(String[] args) {
frame = new ExtractUI();
frame.setVisible(true);
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// frame = new ExtractUI();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
}
/**
* Create the frame.
*/
public ExtractUI() {
setTitle("中文查找/前端多语言替换工具 V1.3.0");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1011, 654);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("查找文件目录:");
lblNewLabel.setBounds(10, 13, 107, 22);
contentPane.add(lblNewLabel);
sourcePath = new JTextField();
sourcePath.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
try {
frame.textchange();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
sourcePath.setBounds(115, 10, 765, 28);
contentPane.add(sourcePath);
sourcePath.setColumns(10);
JButton btnSourcePath = new JButton("选择...");
btnSourcePath.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
frame.getPath(true);
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
btnSourcePath.setBounds(890, 10, 97, 29);
contentPane.add(btnSourcePath);
lblNewLabel_1 = new JLabel("输出文件目录:");
lblNewLabel_1.setBounds(10, 46, 107, 22);
contentPane.add(lblNewLabel_1);
outPath = new JTextField();
outPath.setColumns(10);
outPath.setBounds(115, 43, 765, 28);
contentPane.add(outPath);
btnOutPath = new JButton("选择...");
btnOutPath.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
frame.getPath(false);
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
btnOutPath.setBounds(890, 43, 97, 29);
contentPane.add(btnOutPath);
btnAnalysis = new JButton("分 析");
btnAnalysis.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
frame.analysis();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
btnAnalysis.setBounds(115, 169, 97, 23);
contentPane.add(btnAnalysis);
resultMsg = new JLabel("");
resultMsg.setFont(new Font("宋体", Font.BOLD, 14));
resultMsg.setForeground(Color.RED);
resultMsg.setBounds(10, 578, 977, 29);
contentPane.add(resultMsg);
btnSaveResult = new JButton("分析结果另存为...");
btnSaveResult.setEnabled(false);
btnSaveResult.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
frame.saveResult();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
btnSaveResult.setBounds(239, 169, 141, 23);
contentPane.add(btnSaveResult);
btnSaveWord = new JButton("保存单词");
btnSaveWord.setEnabled(false);
btnSaveWord.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
frame.saveWord();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
btnSaveWord.setBounds(425, 169, 97, 23);
contentPane.add(btnSaveWord);
scrollPane = new JScrollPane();
scrollPane.setBounds(10, 202, 977, 366);
contentPane.add(scrollPane);
resultArea = new JTextArea();
scrollPane.setViewportView(resultArea);
resultArea.setColumns(30);
btnReplace = new JButton("全部替换");
btnReplace.setToolTipText("分析并校验完成后才能使用");
btnReplace.setEnabled(false);
btnReplace.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
frame.replaceAll();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
btnReplace.setBounds(715, 169, 97, 23);
contentPane.add(btnReplace);
btnCheck = new JButton("校验");
btnCheck.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
frame.check();
} catch (Exception e1) {
e1.printStackTrace();
}
}
});
btnCheck.setBounds(561, 169, 114, 23);
contentPane.add(btnCheck);
JLabel lblIgnore = new JLabel("忽略文件(,分隔):");
lblIgnore.setBounds(10, 120, 107, 24);
contentPane.add(lblIgnore);
textIgnore = new JTextField();
textIgnore.setBounds(115, 117, 765, 32);
contentPane.add(textIgnore);
textIgnore.setColumns(10);
JLabel lblkeyFle = new JLabel("已有Key文件:");
lblkeyFle.setBounds(10, 82, 107, 22);
contentPane.add(lblkeyFle);
textkeyFile = new JTextField();
textkeyFile.setColumns(10);
textkeyFile.setBounds(115, 79, 765, 28);
contentPane.add(textkeyFile