Browse Source

Add Has function to Translation

Checking if translation category and word exists has been moved to an
external function where warnings are optional
habeebweeb 4 years ago
parent
commit
4fc7b9ae4f
1 changed files with 11 additions and 6 deletions
  1. 11 6
      COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Translation.cs

+ 11 - 6
COM3D2.MeidoPhotoStudio.Plugin/MeidoPhotoStudio/Translation.cs

@@ -78,21 +78,26 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
             ReloadTranslationEvent?.Invoke(null, EventArgs.Empty);
         }
 
-        public static string Get(string category, string text)
+        public static bool Has(string category, string text, bool warn = false)
         {
             if (!Translations.ContainsKey(category))
             {
-                Debug.LogWarning($"Could not find translation category '{category}'");
-                return text;
+                if (warn) Debug.LogWarning($"Could not find translation category '{category}'");
+                return false;
             }
 
             if (!Translations[category].ContainsKey(text))
             {
-                Debug.LogWarning($"Could not find translation for '{text}' in '{category}'");
-                return text;
+                if (warn) Debug.LogWarning($"Could not find translation for '{text}' in '{category}'");
+                return false;
             }
 
-            return Translations[category][text];
+            return true;
+        }
+
+        public static string Get(string category, string text)
+        {
+            return Has(category, text, true) ? Translations[category][text] : text;
         }
 
         public static string[] GetArray(string category, IEnumerable<string> list)