public static void SearchLocalizationKeys() { var commandManager = new CommandManager(); foreach (var localizationTable in LocalizationOfflineCache.LoadAllBundled()) { Dictionary <string, string> textMap = localizationTable.GetTextMapFor(EditorLocalizationConfiguration.GetMasterCulture()); if (textMap == null) { Debug.LogWarning("Failed to get TextMap for MasterCulture: " + EditorLocalizationConfiguration.GetMasterCulture().DisplayName); return; } foreach (var kvp in textMap) { string key = kvp.Key; string localizedText = kvp.Value; commandManager.AddCommand(new GenericCommand(localizedText, () => { Debug.Log(string.Format("Copied '{0}' into the clipboard!", key)); EditorGUIUtility.systemCopyBuffer = key; }, detailText: key)); } } CommandPaletteWindow.InitializeWindow("Localization Keys..", commandManager, clearInput: true); }
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 + "!"); }); }); }); }