查找代码的中文插件
来源:互联网 发布:程序员鄙视链图 编辑:程序博客网 时间:2024/06/03 19:24
< 最近项目做国际化,虽然在文字内容设计上,做了配表,来帮助实现以后要的国际化。但是还是不可避免有些写在代码中的中文文字。
一.使用vs和正则表达式查找
Ctrl+shift+F,打开查找和替换。查找选项中,勾上使用正则表达式,查找的内容为(“.[\u4E00-\u9FA5]+)|([\u4E00-\u9FA5]+.”) ,可以排除注释中的代码,但是Unity的Deg和或者自定义的Deg代码没办法排除。xml和cs的格式全都找到了。
二.写Unity插件查找
可设置查找路径,排除指定名称的代码,针对个性话Debug筛选。在Console看到所有的查找结果
“`C#
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text;
public class FindChineseTool : MonoBehaviour
{
[MenuItem(“Tools/查找代码中文”)]
public static void Pack()
{
Rect wr = new Rect(300, 400, 400, 100);
FindChineseWindow window = (FindChineseWindow)EditorWindow.GetWindowWithRect(typeof(FindChineseWindow), wr, true, “查找项目中的中文字符”);
window.Show();
}
}
public class FindChineseWindow : EditorWindow
{
private ArrayList csList = new ArrayList();
private int eachFrameFind = 4;
private int currentIndex = 0;
private bool isBeginUpdate = false;
private string outputText;
public string filePath = “/Script”;
private string strForShader= “”;
private void Awake()
{
}private void GetAllFIle(DirectoryInfo dir){ FileInfo[] allFile = dir.GetFiles(); foreach (FileInfo fi in allFile) { //if (fi.DirectoryName.IndexOf("\\Assets\\Develop") == -1)//排除指定路径下的代码 // continue; if(fi.DirectoryName.Contains("FindChineseTool"))//排除指定名称的代码 continue; if (fi.FullName.IndexOf(".meta") == -1 && fi.FullName.IndexOf(".cs") != -1) { csList.Add(fi.DirectoryName + "/" + fi.Name); } } DirectoryInfo[] allDir = dir.GetDirectories(); foreach (DirectoryInfo d in allDir) { GetAllFIle(d); }}public void OnGUI(){ EditorGUILayout.BeginHorizontal(); strForShader = GUILayout.TextArea(filePath, GUIStyle.none); //Debug.Log("&& 图片名字:"+ str); if (GUILayout.Button("粘贴", GUILayout.Width(100))) { TextEditor te = new TextEditor(); te.Paste(); strForShader = te.content.text; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(outputText, EditorStyles.boldLabel); if (GUILayout.Button("开始遍历项目")) { csList.Clear(); DirectoryInfo d = new DirectoryInfo(Application.dataPath + filePath); GetAllFIle(d); GetAllFIle(d); outputText = "游戏内代码文件的数量:" + csList.Count; isBeginUpdate = true; outputText = "开始遍历项目"; } EditorGUILayout.EndHorizontal();}void Update(){ if (isBeginUpdate && currentIndex < csList.Count) { int count = (csList.Count - currentIndex) > eachFrameFind ? eachFrameFind : (csList.Count - currentIndex); for (int i = 0; i < count; i++) { string url = csList[currentIndex].ToString(); currentIndex = currentIndex + 1; url = url.Replace("\\", "/"); printChinese(url); } if (currentIndex >= csList.Count) { isBeginUpdate = false; currentIndex = 0; outputText = "遍历结束,总共" + csList.Count; } }}private bool HasChinese(string str){ return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");}private Regex regex = new Regex("\"[^\"]*\"");private void printChinese(string path){ if (File.Exists(path)) { string[] fileContents = File.ReadAllLines(path, Encoding.Default); int count = fileContents.Length; for (int i = 0; i < count; i++) { string printStr = fileContents[i].Trim(); if (printStr.IndexOf("//") == 0) //说明是注释 continue; if (printStr.IndexOf("Debug.Log") == 0) //说明是注释 continue; //if (printStr.IndexOf("ALog.Log") == 0) //说明是注释 // continue; MatchCollection matches = regex.Matches(printStr); foreach (Match match in matches) { if (HasChinese(match.Value)) { Debug.Log("路径:" + path + " 行数:" + i + " 内容:" + printStr); break; } } } fileContents = null; }}
}
“`
在找出所有带中文的代码后,然后就可以处理了。
* 大概思路是把路径和文字内容以及生成数字编号,以分号分隔生成txt文本
* 把txt文本导入xlsx中,以文本分隔为”,”。导入后把简体中文转换为繁体中文(中间具体内容项目原因不方便透露)
* 有转换后的表格的id。再通过替换,把简体中文替换为id。
- 查找代码的中文插件
- 查找unity工程代码中中文字符
- ibatis 中文查找的问题
- visual studio c# 查找代码中含有中文的行 要求该行非注释、非#region
- Eclipse 中文插件的安装
- Eclipse 中文插件的安装
- Tips:使用Xcode查找项目中的中文字符串,代码国际化
- 查找历史纪录的代码
- grep 查找目录中文件的字符串
- PHP查找中文字符的解决方案
- elasticsearch中文汉字的精确查找
- 查找String中中文的个数
- PHP查找中文字符的解决方案
- firefox查找插件和插件媒体类型的方法
- 查找字符串中是否有中文以及中文的个数
- Eclipse 代码折叠的插件
- WizKnowledge的插入代码插件
- ButterKnife代码生成的插件
- 1171 保留整数 sdut
- 功能错误小结
- 震惊!微信公众号的真相!
- 关于ComponentName的使用
- 3.偏头痛杨的Java入门教学系列之表达式&运算符&关键字&标识符&表达式篇
- 查找代码的中文插件
- 理解Flink(一):数据流编程模型
- springMVC 访问过程
- 若干题目2
- C++入门——排序
- 定制Spring Boot的Banner
- CentOS7下安装solr服务器
- 微信公众号开发---模板消息url
- 你是不是想要个ideal汉化包?我这里有啊~