void AddData(LocalizationKeyword type, string value) { if (Data.ContainsKey(type)) { Data[type] = value; } else { Data.Add(type, value); } }
/// <summary> /// Returns the Content type that matches the desired one /// </summary> /// <param name="contentString"></param> /// <returns></returns> public LocalizationKeyword GetDataType(string contentString) { LocalizationKeyword type = LocalizationKeyword.ERROR; if (localizationTypeTable.TryGetValue(contentString, out type)) { return(type); } Debug.LogError("The TextType \"" + contentString + "\" does not exist."); return(LocalizationKeyword.ERROR); }
/// <summary> /// Get the translation of a provided text /// </summary> /// <param name="request">Text to translate</param> /// <returns>The string representing the translation of the request</returns> public string Translate(LocalizationKeyword request) { string value = ""; if (Data.TryGetValue(request, out value)) { return(value); } Debug.LogError("There's no record of a text of type \"" + request.ToString() + "\" in the language \"" + language.ToString() + "\"."); return(null); }
/// <summary> /// Creates the conversion table between string and content type /// </summary> void InitializeLocalizationKeywordDictionary() { localizationTypeTable = new Dictionary <string, LocalizationKeyword>(); System.Array A = System.Enum.GetValues(typeof(LocalizationKeyword)); if (A.Length == 0) { throw new System.ArgumentException("Enum " + typeof(LocalizationKeyword).ToString() + " is empty", "array"); } for (int i = 0; i < A.Length; i++) { LocalizationKeyword locType = (LocalizationKeyword)A.GetValue(i); localizationTypeTable.Add(locType.ToString(), locType); } }
/// <summary> /// Get the translation of a specified text on a certain language /// </summary> /// <param name="content">Text to translate</param> /// <param name="customLanguage">To what language will the text be translated to?</param> /// <returns></returns> public string CustomTranslate(LocalizationKeyword content, LocalizationLanguage customLanguage) { if (!alreadyInitialized) { InitializeSystems(); } LocalizationData data; if (languages.TryGetValue(customLanguage, out data)) { string result = data.Translate(content); //Check if the consulted language has a translation for such text if (result == null) { //If the consulted language is the one set as default or fallback, return "ERROR". if (customLanguage == defaultLanguage) { string contentString = content.ToString(); Debug.LogError("There's no match in the language \"" + customLanguage.ToString() + "\" for \"" + contentString + "\""); return(contentString); } else { return(CustomTranslate(content, defaultLanguage)); } } return(result); } if (customLanguage == defaultLanguage) { Debug.LogError("There's no record of the language \"" + customLanguage.ToString() + "\"."); return("[ERROR]"); } else { Debug.LogError("There's no record of the language \"" + customLanguage.ToString() + "\". The default language will be used."); return(CustomTranslate(content, defaultLanguage)); } }
/// <summary> /// Get the translation of a specified text on a certain language /// </summary> /// <param name="content">Text to translate</param> /// <param name="preference">How should the text be translated?</param> /// <returns></returns> public string Translate(LocalizationKeyword content, LocalizationPreference preference) { if (!alreadyInitialized) { InitializeSystems(); } switch (preference) { case LocalizationPreference.DEFAULT: if (preferSystemLanguage) { goto case LocalizationPreference.SYSTEM; } else { return(CustomTranslate(content, defaultLanguage)); } /*if (Languages.TryGetValue(defaultLanguage, out startingLanguageData)) * return startingLanguageData.CustomTranslate(request); * break;*/ case LocalizationPreference.SYSTEM: return(CustomTranslate(content, systemLanguage)); /*if (Languages.TryGetValue(systemLanguage, out startingLanguageData)) * return startingLanguageData.CustomTranslate(request); * break;*/ case LocalizationPreference.CUSTOM: Debug.LogWarning("Translations using CUSTOM as a preference should use CustomTranslate instead. The default language will be used instead."); goto case LocalizationPreference.DEFAULT; default: Debug.LogWarning("Preference type \"" + preference.ToString() + "\" could not be found. The default language will be used instead."); goto case LocalizationPreference.DEFAULT; } }
public void SetTextContent(LocalizationKeyword newType) { content = newType; GetTextTranslated(); }
/// <summary> /// Get the translation of a provided text /// </summary> /// <param name="request">Text to translate</param> /// <returns>The string representing the translation of the request</returns> public string Translate(LocalizationKeyword request) { string value = ""; if (Data.TryGetValue(request, out value)) { return value; } Debug.LogError("There's no record of a text of type \"" + request.ToString() + "\" in the language \"" + language.ToString() + "\"."); return null; }