IEnumerator loadLanguage(Language language) { System.DateTime started = System.DateTime.Now; string filePath = Path.Combine(Application.streamingAssetsPath, "Languages/" + language.getFileName()); languageString = ""; if (filePath.Contains("://")) { WWW www = new WWW(filePath); yield return(www); languageString = www.text; } else { languageString = File.ReadAllText(filePath); } localizedText = SerializedNestedStrings.deserialize(languageString); System.TimeSpan timeElapsed = System.DateTime.Now - started; Debug.Log("Language " + language.getFileName() + " loaded in " + timeElapsed.TotalMilliseconds + "ms"); PrefsHelper.setPreferredLanguage(language.getLanguageID()); languageFontMetadata = localizedText.getSubData("meta.font"); loadedLanguageIsComplete = false; loadedLanguage = language; languageString = ""; loadedLanguageIsComplete = getLocalizedValue("generic.complete", "N").Equals("Y", System.StringComparison.OrdinalIgnoreCase); if (onLanguageChanged != null) { onLanguageChanged(language); } }
IEnumerator loadLanguage(Language language) { System.DateTime started = System.DateTime.Now; string filePath = Path.Combine(Application.streamingAssetsPath, "Languages/" + language.getFileName()); languageString = ""; if (filePath.Contains("://")) { WWW www = new WWW(filePath); yield return(www); languageString = www.text; } else { languageString = File.ReadAllText(filePath); } localizedText = SerializedNestedStrings.deserialize(languageString); System.TimeSpan timeElapsed = System.DateTime.Now - started; Debug.Log("Language " + language.getFileName() + " loaded in " + timeElapsed.TotalMilliseconds + "ms"); PrefsHelper.setPreferredLanguage(language.getLanguageID()); loadedLanguage = language; languageString = ""; }
public void loadLocalizedText(string filename) { string filePath = Path.Combine(Application.streamingAssetsPath, filename); if (!File.Exists(filePath)) { filePath = filePath.Replace(language, "English"); Debug.Log("Language " + language + " not found. Using English"); language = "English"; } if (File.Exists(filePath)) { System.DateTime started = System.DateTime.Now; localizedText = SerializedNestedStrings.deserialize(File.ReadAllText(filePath)); System.TimeSpan timeElapsed = System.DateTime.Now - started; Debug.Log("Language " + language + " loaded successfully. Deserialization time: " + timeElapsed.TotalMilliseconds + "ms"); } else { Debug.LogError("No English json found!"); } }
public List <LanguageFontCharData> GetMissingFontCharData(TMPFont forceFont = null, Language forceLanguage = null) { string fullLanguagesPath = Path.Combine(Application.dataPath, languagesPath); string fullCharsPath = Path.Combine(Application.dataPath, charsPath); var missingCharData = new List <LanguageFontCharData>(); foreach (var language in LanguagesData.instance.languages) { if (forceLanguage != null && forceLanguage != language) { continue; } var filePath = Path.Combine(fullLanguagesPath, language.getFileName()); var fontDict = SerializedNestedStrings.deserialize(File.ReadAllText(filePath)).getSubData("meta.font").subData; foreach (var fontKVPair in fontDict) { if (LocalizationManager.parseFontCompabilityString(language, fontKVPair.Value.value)) { // Font is marked as compatible var font = TMPFontsData.instance.fonts.FirstOrDefault(a => a.idName.Equals(fontKVPair.Key)); if (forceFont != null && forceFont != font) { continue; } if (font == null) { Debug.LogWarning(fontKVPair.Key + " is missing from TMP Fonts Data asset"); continue; } if (font.fontAsset == null) { Debug.LogWarning(fontKVPair.Key + " is missing associated TMPro font in TMP Fonts asset"); continue; } var charString = File.ReadAllText(Path.Combine(fullCharsPath, language.getFileName() + "Chars.txt")); charString = string.Join("", charString.Distinct()); List <char> currentChars = charString.ToCharArray().ToList(); currentChars.Add('a'); // Check fonts AND fallbacks var fallbackList = new List <TMP_FontAsset>(); fallbackList.Add(font.fontAsset); // Current language fallbackList.AddRange(font.fontAsset.fallbackFontAssets); // language's fallbacks fallbackList.AddRange(TMP_Settings.fallbackFontAssets); // Global fallbacks fallbackList = fallbackList.Distinct().ToList(); foreach (var fontAsset in fallbackList) { var missingChars = new List <char>(); // NO idea why but the hasCharacters() function seems to just be true all the time, so also check for null/any missingChars = currentChars.Where(a => !fontAsset.characterDictionary.ContainsKey((int)a)).ToList(); if (missingChars != null && missingChars.Any()) { currentChars = missingChars; } else { currentChars = null; break; } } if (currentChars != null) { currentChars = currentChars.Except(ignoreChars.ToCharArray()).ToList(); if (currentChars.Any()) { missingCharData.Add(new LanguageFontCharData(language, font, string.Join("", currentChars))); } } } } } return(missingCharData .OrderBy(a => a.font.fontAsset.name) .ThenBy(a => a.language.getLanguageID()) .ToList()); }