예제 #1
0
        public void Translater(TranslateMapper transMap)
        {
            if (transMap.FilePath.Contains("Editor"))
            {
                return;
            }

            Regex rx = new Regex("[\u4e00-\u9fa5]+");

            string[] lines = File.ReadAllLines(transMap.FilePath);

            Regex reg = new Regex("\"[^\"]*\"");

            for (int i = 0; i < lines.Length; i++)
            {
                if (isFilter(lines[i]))
                {
                    continue;
                }

                MatchCollection mc = reg.Matches(lines[i]);
                foreach (Match m in mc)
                {
                    if (rx.IsMatch(m.Value))
                    {
                        //翻译替换
                        string format = m.Value.Substring(1, m.Value.Length - 2);
                        lines[i] = lines[i].Replace(format, transMap.Translate(format));
                    }
                }
            }

            //保存文件
            File.WriteAllLines(transMap.FilePath, lines);
        }
예제 #2
0
        public void Translater(TranslateMapper transMap)
        {
            Regex rx = new Regex("[\u4e00-\u9fa5]+");

            GameObject prefab   = AssetDatabase.LoadAssetAtPath(transMap.FilePath, typeof(GameObject)) as GameObject;
            GameObject instance = GameObject.Instantiate(prefab) as GameObject;

#if NGUI
            UILabel[] labels = instance.GetComponentsInChildren <UILabel>(true);
            for (int q = 0; q < labels.Length; q++)
            {
                string labText = labels[q].text.Trim();
                if (string.IsNullOrEmpty(labText))
                {
                    continue;
                }

                labText = labText.Replace("\n", @"\n").Replace("\r", "");
                if (rx.IsMatch(labText))    //翻译替换
                {
                    labels[q].text = transMap.Translate(labText);
                }
            }

            // UIInput中的默认文本
            UIInput[] inputs = instance.GetComponentsInChildren <UIInput>(true);
            for (int q = 0; q < inputs.Length; q++)
            {
                string text = inputs[q].value.Trim();
                if (string.IsNullOrEmpty(text))
                {
                    continue;
                }

                text = text.Replace("\n", @"\n").Replace("\r", "");
                if (rx.IsMatch(text))
                {
                    inputs[q].value = transMap.Translate(text);
                }
            }

            PrefabUtility.ReplacePrefab(instance, prefab);
#endif
            GameObject.DestroyImmediate(instance);
        }