static void ParseTermsInScripts() { EditorApplication.update -= ParseTermsInScripts; string[] scriptFiles = AssetDatabase.GetAllAssetPaths().Where(path => path.ToLower().EndsWith(".cs")).ToArray(); string mLocalizationManager = @"GetTranslation\s?\(\s?\""(.*?)\"""; string mLocalizationManagerOld = @"GetTermTranslation\s?\(\s?\""(.*?)\"""; string mLocalizationManagerTry = @"TryGetTranslation\s?\(\s?\""(.*?)\"""; string mSetTerm = @"SetTerm\s?\(\s?\""(.*?)\"""; Regex regex = new Regex(mLocalizationManager + "|" + mLocalizationManagerTry + "|" + mLocalizationManagerOld + "|" + mSetTerm, RegexOptions.Multiline); foreach (string scriptFile in scriptFiles) { string scriptContents = File.ReadAllText(scriptFile); MatchCollection matches = regex.Matches(scriptContents); for (int matchNum = 0; matchNum < matches.Count; matchNum++) { Match match = matches[matchNum]; string term = I2Utils.GetCaptureMatch(match); GetParsedTerm(term).Usage++; } } ScheduleUpdateTermsToShowInList(); }
static void ParseNonTranslatableElements(ref TranslationQuery query) { //\[i2nt].*\[\/i2nt] var matches = Regex.Matches(query.Text, @"\{\[(.*?)]}|\[(.*?)]|\<(.*?)>"); if (matches == null || matches.Count == 0) { return; } string finalText = query.Text; List <string> finalTags = new List <string>(); for (int i = 0, imax = matches.Count; i < imax; ++i) { var tag = I2Utils.GetCaptureMatch(matches[i]); int iClosingTag = FindClosingTag(tag, matches, i); // find [/tag] or </tag> if (iClosingTag < 0) { // Its not a tag, its a parameter var fulltag = matches[i].ToString(); if (fulltag.StartsWith("{[") && fulltag.EndsWith("]}")) { finalText = finalText.Replace(fulltag, GetGoogleNoTranslateTag(finalTags.Count) + " "); // 0x2600 is the start of the UNICODE Miscellaneous Symbols table, so they are not going to be translated by google //finalText = finalText.Replace(fulltag, /*"{[" + finalTags.Count + "]}"*/ ((char)(0x2600 + finalTags.Count)).ToString()); // 0x2600 is the start of the UNICODE Miscellaneous Symbols table, so they are not going to be translated by google finalTags.Add(fulltag); } continue; } if (tag == "i2nt") { var tag1 = query.Text.Substring(matches[i].Index, (matches[iClosingTag].Index - matches[i].Index) + matches[iClosingTag].Length); finalText = finalText.Replace(tag1, GetGoogleNoTranslateTag(finalTags.Count) + " "); //finalText = finalText.Replace(tag1, /*"{[" + finalTags.Count + "]}"*/ ((char)(0x2600 + finalTags.Count)).ToString()); finalTags.Add(tag1); } else { var tag1 = matches[i].ToString(); finalText = finalText.Replace(tag1, GetGoogleNoTranslateTag(finalTags.Count) + " "); //finalText = finalText.Replace(tag1, /*"{[" + finalTags.Count + "]}"*/ ((char)(0x2600 + finalTags.Count)).ToString()); finalTags.Add(tag1); var tag2 = matches[iClosingTag].ToString(); finalText = finalText.Replace(tag2, GetGoogleNoTranslateTag(finalTags.Count) + " "); //finalText = finalText.Replace(tag2, /*"{[" + finalTags.Count + "]}"*/ ((char)(0x2600 + finalTags.Count)).ToString()); finalTags.Add(tag2); } } query.Text = finalText; query.Tags = finalTags.ToArray(); }
static int FindClosingTag(string tag, MatchCollection matches, int startIndex) { for (int i = startIndex, imax = matches.Count; i < imax; ++i) { var newTag = I2Utils.GetCaptureMatch(matches[i]); if (newTag[0] == '/' && tag.StartsWith(newTag.Substring(1))) { return(i); } } return(-1); }