private static void PreBuild() { previousScriptingDefines_ = ScriptingDefinesManager.GetCurrentDefines(); LocalizationOfflineCache.CacheBundledLocalizationTables(); TMPLocalization.DownloadAndBakeAllUsedLocalizationCharactersIntoFonts(); ScriptingDefinesManager.AddDefineIfNotFound("BUILT_WITH_BUILD_PIPELINE"); }
public static void AddNewLocalizationKey() { if (Application.internetReachability == NetworkReachability.NotReachable) { Debug.LogWarning("No internet connection - cannot add new localization key!"); return; } CheckAndUpdateCurrentDatabaseSource(() => { CommandPaletteArgumentWindow.Show("Set Localization Key", (localizationKey) => { CultureInfo masterCulture = EditorLocalizationConfiguration.GetMasterCulture(); CommandPaletteArgumentWindow.Show(string.Format("Set {0} Text", masterCulture.EnglishName), (masterText) => { ITable <GLocalizationMasterRowData> localizationMasterTable = currentDatabaseSource_.LoadLocalizationMasterTable(); if (localizationMasterTable == null) { return; } ITable <GLocalizationRowData> localizationEntryTable = currentDatabaseSource_.LoadLocalizationEntriesTable(); if (localizationEntryTable == null) { return; } GoogleTranslate translation = GoogleTranslateSource.FindAndCreate(); if (translation == null) { return; } bool existingKey = localizationMasterTable.FindAll().Any(r => r.Element.Key == localizationKey); if (existingKey) { Debug.LogWarning("Found existing row for localization key: " + localizationKey + " cannot adding as new!"); return; } var rowData = new GLocalizationMasterRowData(); rowData.Key = localizationKey; localizationMasterTable.Add(rowData); // NOTE (darren): we don't delete pre-existing entries in case of data loss bool duplicateKey = localizationEntryTable.FindAll().Any(r => r.Element.Key == localizationKey); if (duplicateKey) { Debug.LogWarning("Found pre-existing rows for localization key: " + localizationKey + ", please verify that they are correct - will not be deleted!"); } foreach (var supportedCulture in EditorLocalizationConfiguration.GetSupportedCultures()) { bool isMasterText = supportedCulture.Equals(masterCulture); string translatedText; if (isMasterText) { translatedText = masterText; } else { translatedText = translation.Translate(masterText, masterCulture.TwoLetterISOLanguageName, supportedCulture.TwoLetterISOLanguageName); } var entryRowData = new GLocalizationRowData(); entryRowData.Key = localizationKey; entryRowData.LanguageCode = supportedCulture.Name; entryRowData.LocalizedText = translatedText; entryRowData.SetNeedsUpdating(!isMasterText); localizationEntryTable.Add(entryRowData); } // Cache bundled localization tables after new row LocalizationOfflineCache.CacheBundledLocalizationTables(); // Rebake fonts after new translations TMPLocalization.DownloadAndBakeAllUsedLocalizationCharactersIntoFonts(); Debug.Log("Finished adding new key: " + localizationKey + " to: " + currentDatabaseSource_.TableKey + "!"); }); }); }); }