public static string Translate(string input, object obj) { GUIUtility.systemCopyBuffer = input; if (string.IsNullOrEmpty(input)) { return(input); } // Consider changing this! You have a dictionary, but you iterate instead of making a lookup. Why do you not use the WeakKeyDictionary, you have instead? if (!originalTranslations.Any(x => x.Key.Target == obj)) //check if we don't have the object in the dictionary { //add to untranslated list originalTranslations.Add(new WeakReference(obj), input); } string translation; if (translations.TryGetValue(input.Trim(), out translation)) { return(translation); } else if (obj is Text) { var immediatelyTranslated = OnUnableToTranslateUGUI?.Invoke(obj, input); if (immediatelyTranslated != null) { return(immediatelyTranslated); } } else if (obj is TMP_Text) { var immediatelyTranslated = OnUnableToTranslateTextMeshPro?.Invoke(obj, input); if (immediatelyTranslated != null) { return(immediatelyTranslated); } } // Consider changing this! You make a value lookup in a dictionary, which scales really poorly if (!untranslated.Contains(input) && !translations.ContainsValue(input)) { untranslated.Add(input); } return(input); }
internal static string OnOnUnableToTranslateUgui(object arg1, string arg2) { return(OnUnableToTranslateUGUI?.Invoke(arg1, arg2)); }