284 lines
9.8 KiB
C#
284 lines
9.8 KiB
C#
using System.Collections.Generic;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
using System.IO;
|
||
using UnityEngine.UI;
|
||
using BF;
|
||
using System;
|
||
using System.Text;
|
||
using BFEditor.Resource;
|
||
|
||
namespace BFEditor
|
||
{
|
||
public static class LocalizationMenuTools
|
||
{
|
||
#region LocalizationTools
|
||
//写入策划工具和lua
|
||
private const string DefaultFontName = "font_cn"; //默认字体
|
||
static private string PythonToolPath = Application.dataPath + "/../Tools/localization";
|
||
static private string ExcelFilePath = Application.dataPath + "/LocalConfig/global.txt";
|
||
static private string LuaFilePath = Application.dataPath + "/Developer/lua/app/config/localization/cn/global.lua";
|
||
static private string ShellFile = PythonToolPath + "/launch.sh";
|
||
static private string CheckValidMsg = string.Empty;
|
||
static private StringBuilder CatConfigStringBuilder = new StringBuilder(1024);
|
||
static private string[] CatConfigPaths = new string[]
|
||
{
|
||
"Assets/Developer/lua/app/config/localization/cn/global.lua"
|
||
};
|
||
|
||
static private bool CheckLocalizeDataValid(string key, string value, string fontName, bool ignoreValue, bool genLua = true)
|
||
{
|
||
CheckValidMsg = string.Empty;
|
||
|
||
string luaPath = genLua ? " " + LuaFilePath : "";
|
||
fontName = string.IsNullOrEmpty(fontName) ? "null" : fontName;
|
||
BFEditorUtils.RunCommond("sh", "launch.sh " + ExcelFilePath + " " + key + " " + value + " " + ignoreValue + " " + fontName + luaPath, PythonToolPath, (msg) =>
|
||
{
|
||
CheckValidMsg = msg;
|
||
Debug.Log(CheckValidMsg);
|
||
}, (error) =>
|
||
{
|
||
CheckValidMsg = error;
|
||
if (string.IsNullOrEmpty(CheckValidMsg))
|
||
CheckValidMsg = "error";
|
||
});
|
||
|
||
return CheckValidMsg.Equals("success");
|
||
}
|
||
|
||
static public string CatWordsFromLuaConfig(List<string> luaFolderPath)
|
||
{
|
||
HashSet<char> wordsHash = new HashSet<char>();
|
||
if (luaFolderPath.Count == 0)
|
||
{
|
||
var str = "";
|
||
CheckUnicode(str, ref wordsHash);
|
||
}
|
||
else
|
||
{
|
||
|
||
foreach (var luaDir in luaFolderPath)
|
||
{
|
||
if (!Directory.Exists(luaDir))
|
||
{
|
||
Debug.LogWarning("多语言表中不存在 " + luaDir);
|
||
var str = "";
|
||
CheckUnicode(str, ref wordsHash);
|
||
}
|
||
else
|
||
{
|
||
var dir = new DirectoryInfo(luaDir);
|
||
var files = dir.GetFiles("*.lua");
|
||
if (null != files)
|
||
{
|
||
int len = files.Length;
|
||
for (int i = 0; i < len; i++)
|
||
{
|
||
var fileInfo = files[i];
|
||
var content = File.ReadAllText(fileInfo.FullName);
|
||
if (content.Contains("·"))
|
||
{
|
||
Debug.Log("包含不能处理字符" + fileInfo.FullName);
|
||
}
|
||
CheckUnicode(content, ref wordsHash);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
CatConfigStringBuilder.Remove(0, CatConfigStringBuilder.Length);
|
||
foreach (var c in wordsHash)
|
||
{
|
||
CatConfigStringBuilder.Append(c);
|
||
}
|
||
var result = CatConfigStringBuilder.ToString();
|
||
|
||
return result;
|
||
}
|
||
|
||
static private List<char> Punctuations = new List<char>()
|
||
{
|
||
',', '.', '?', '!', '@', '#', '$', '%', '^', '(', ')', '_', '+', '=', '{', '}',
|
||
'|', '"', ':', ';', '/', '>', '<', '`', '~', ',', '。', ';', '‘', '【', '】',
|
||
'、', '-', '·', '《', '》', '?', '“', '”', ':', '」', '「', '—', ')', '(', '*',
|
||
'&', '…', '¥', '!', '~', '『', '』', '.', '\\', '\'', '[', ']', ' ', '«', '»', '–',
|
||
'↑', '↓', '/', '‘', '’', '“', '”',
|
||
};
|
||
|
||
static private List<char> Digitals = new List<char>()
|
||
{
|
||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||
};
|
||
|
||
static private List<char> EnglishLitters = new List<char>()
|
||
{
|
||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '\'',
|
||
};
|
||
|
||
static private List<char> CurrencySign = new List<char>()
|
||
{
|
||
'؋', '฿', '₵', '₡', '¢', '$', '₫', '֏', '€', 'ƒ', '₣', '₲', '₴', '₾',
|
||
'₭', '₺', '₼', '₦', '₱', '£', 'Q', '﷼', '៛', '₽', '₹', /*'Rp'*/
|
||
'૱', '௹', 'C', '₨', '₪', '₸', '₮', '¥'
|
||
};
|
||
|
||
static private List<char> FrenchSign = new List<char>()
|
||
{
|
||
'ü', 'û', 'ù', 'œ', 'ô', 'ï', 'î', 'ë', 'ê', 'è', 'é', 'ç', 'æ', 'â', 'à', 'Ü',
|
||
'Û', 'Ù', 'Œ', 'Ô', 'Ï', 'Î', 'Ë', 'Ê', 'È', 'É', 'Ç', 'Æ', 'Â', 'À', 'Ÿ', 'ÿ', '«', '»'
|
||
};
|
||
|
||
static private List<char> GermanSign = new List<char>()
|
||
{
|
||
'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ẞ', 'ß', '„',
|
||
};
|
||
|
||
static private List<char> PortugueseSign = new List<char>()
|
||
{
|
||
'Á', 'á', 'Â', 'â', 'Ã', 'ã', 'À', 'à', 'Ç', 'ç', 'É', 'é',
|
||
'Ê', 'ê', 'Í', 'í', 'Ó', 'ó', 'Ô', 'ô', 'Õ', 'õ', 'Ú', 'ú',
|
||
'Ü', 'ü',
|
||
};
|
||
|
||
static private List<char> SpanishSign = new List<char>()
|
||
{
|
||
'á', 'í', 'ó', 'ú', 'ñ', 'Ñ', 'ª', 'º', '¿', '¡', 'Á', 'É',
|
||
'Ó', 'Í', 'Ú', 'Ü', 'é', 'ü',
|
||
};
|
||
|
||
|
||
static private List<char> TurkeySign = new List<char>()
|
||
{
|
||
'Ç', 'ç', 'Ğ', 'ğ', 'I', 'ı', 'İ', 'i', 'Ö', 'ö', 'Ş', 'ş', 'Ü', 'ü',
|
||
'Â', 'â', 'Î', 'î', 'Û', 'û'
|
||
};
|
||
|
||
static private List<char> Russian = new List<char>()
|
||
{
|
||
'А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж', 'ж', 'З', 'з', 'И', 'и', 'Й',
|
||
'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'У', 'у',
|
||
'Ф', 'ф', 'Х', 'х', 'Ц', 'ц', 'Ч', 'ч', 'Ш', 'ш', 'Щ', 'щ', 'Ъ', 'ъ', 'Ь', 'ь', 'Э', 'э', 'Ю', 'ю', 'Я',
|
||
'я', 'Ы', 'ы'
|
||
};
|
||
|
||
static private List<char> Thailand = new List<char>()
|
||
{
|
||
'ก', 'ข', 'ค', 'ฆ', 'ง', 'จ', 'ฉ', 'ช', 'ซ', 'ฌ', 'ญ', 'ฎ', 'ฏ', 'ฐ', 'ฑ', 'ฒ', 'ณ',
|
||
'ด', 'ต', 'ถ', 'ท', 'ธ', 'น', 'บ', 'ป', 'ผ', 'ฝ', 'พ', 'ฟ', 'ภ', 'ม', 'ย', 'ร', 'ล',
|
||
'ว', 'ศ', 'ษ', 'ส', 'ห', 'ฬ', 'อ', 'ฮ'
|
||
};
|
||
|
||
static private List<char> Italian = new List<char>()
|
||
{
|
||
'À', 'Á', 'È', 'Ì', 'Í', 'Î', 'Ò', 'Ó', 'Ù', 'Ú', 'à', 'á', 'è', 'é', 'ì', 'í', 'î','ò', 'ó', 'ù', 'ú'
|
||
};
|
||
|
||
static private void CheckUnicode(string text, ref HashSet<char> result)
|
||
{
|
||
if (!string.IsNullOrEmpty(text))
|
||
{
|
||
foreach (var c in text)
|
||
{
|
||
result.TryAdd(c);
|
||
// //中文
|
||
// if (c >= 0x4e00 && c <= 0x9fa5)
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //数字
|
||
// if (c >= 0x0030 && c <= 0x0039)
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //英文
|
||
// if ((c >= 0x0061 && c <= 0x007a) ||
|
||
// (c >= 0x0041 && c <= 0x005a))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //罗马数字 1-12
|
||
// if (c >= '\u2160' && c <= '\u216b')
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //标点符号
|
||
// if (Punctuations.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //法语字母
|
||
// if (FrenchSign.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //德语字母
|
||
// if (GermanSign.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //葡萄牙字母
|
||
// if (PortugueseSign.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //西班牙字母
|
||
// if (SpanishSign.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //土耳其字母
|
||
// if (TurkeySign.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //泰语字母
|
||
// if ((c >= '\u0E01' && c <= '\u0E5B') || Thailand.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //俄罗斯字母
|
||
// if (Russian.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
|
||
// //意语
|
||
// if (Italian.Contains(c))
|
||
// {
|
||
// result.TryAdd(c);
|
||
// }
|
||
}
|
||
}
|
||
|
||
for (int i = 0; i < Punctuations.Count; i++)
|
||
result.TryAdd(Punctuations[i]);
|
||
|
||
for (int i = 0; i < Digitals.Count; i++)
|
||
result.TryAdd(Digitals[i]);
|
||
|
||
for (int i = 0; i < EnglishLitters.Count; i++)
|
||
result.TryAdd(EnglishLitters[i]);
|
||
|
||
for (int i = 0; i < CurrencySign.Count; i++)
|
||
result.TryAdd(CurrencySign[i]);
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|