/// <summary> /// Invoked by the menu system to create a new localization on the /// currently selected objects with a given language. /// </summary> /// <param name="language">The language to use. This must be a /// string.</param> private void CreateLocalizationWithLanguage(object language) { if (!(language is string theLanguage)) { throw new ArgumentException("Expected to receive a string", nameof(language)); } if (serializedObject.isEditingMultipleObjects) { Debug.LogWarning($"Can't create a new {nameof(Localization)} when multiple objects are selected"); return; } LocalizationDatabaseUtility.CreateLocalizationWithLanguage(serializedObject, theLanguage); }
public void YarnImporterUtility_CanCreateLocalizationInLocalizationDatabase() { // Arrange: Import a yarn script and create a localization // database for it string fileName = Path.GetRandomFileName(); string path = Path.Combine("Assets", fileName + ".yarn"); createdFilePaths.Add(path); File.WriteAllText(path, TestYarnScriptSource); AssetDatabase.Refresh(); var importer = AssetImporter.GetAtPath(path) as YarnImporter; var importerSerializedObject = new SerializedObject(importer); YarnImporterUtility.CreateNewLocalizationDatabase(importerSerializedObject); createdFilePaths.Add(AssetDatabase.GetAssetPath(importer.localizationDatabase)); var databaseSerializedObject = new SerializedObject(importer.localizationDatabase); // Act: Create a new localization CSV file for some new language LocalizationDatabaseUtility.CreateLocalizationWithLanguage(databaseSerializedObject, AlternateLocaleCode); YarnImporterUtility.CreateLocalizationForLanguageInProgram(importerSerializedObject, AlternateLocaleCode); foreach (var loc in importer.localizationDatabase.Localizations) { createdFilePaths.Add(AssetDatabase.GetAssetPath(loc)); } foreach (var loc in importer.localizations) { createdFilePaths.Add(AssetDatabase.GetAssetPath(loc.text)); } importer.SaveAndReimport(); // Assert: Verify that it exists, contains the string table // entries we expect, and has the language we expect. var expectedLanguages = new HashSet <string> { importer.baseLanguageID, AlternateLocaleCode }.OrderBy(n => n); var foundLanguages = importer.programContainer.localizations.Select(l => l.languageName).OrderBy(n => n); CollectionAssert.AreEquivalent(expectedLanguages, foundLanguages, $"The locales should be what we expect to see"); }
public void YarnImporterUtility_CanUpdateLocalizedCSVs_WhenBaseScriptChanges() { // Arrange: Import a yarn script and create a localization // database for it, create an alternate localization for it string fileName = Path.GetRandomFileName(); string path = Path.Combine("Assets", fileName + ".yarn"); createdFilePaths.Add(path); File.WriteAllText(path, TestYarnScriptSource); AssetDatabase.Refresh(); var importer = AssetImporter.GetAtPath(path) as YarnImporter; var importerSerializedObject = new SerializedObject(importer); YarnImporterUtility.CreateNewLocalizationDatabase(importerSerializedObject); var localizationDatabaseSerializedObject = new SerializedObject(importer.localizationDatabase); LocalizationDatabaseUtility.CreateLocalizationWithLanguage(localizationDatabaseSerializedObject, AlternateLocaleCode); YarnImporterUtility.CreateLocalizationForLanguageInProgram(importerSerializedObject, AlternateLocaleCode); var unmodifiedBaseStringsTable = StringTableEntry.ParseFromCSV((importerSerializedObject.targetObject as YarnImporter).baseLanguage.text); var unmodifiedLocalizedStringsTable = StringTableEntry.ParseFromCSV((importerSerializedObject.targetObject as YarnImporter).localizations.First(l => l.languageName == AlternateLocaleCode).text.text); // Act: modify the imported script so that lines are added, // changed and deleted, and then update the localized CSV // programmatically File.WriteAllText(path, TestYarnScriptSourceModified); AssetDatabase.Refresh(); YarnImporterUtility.UpdateLocalizationCSVs(importerSerializedObject); var modifiedBaseStringsTable = StringTableEntry.ParseFromCSV((importerSerializedObject.targetObject as YarnImporter).baseLanguage.text); var modifiedLocalizedStringsTable = StringTableEntry.ParseFromCSV((importerSerializedObject.targetObject as YarnImporter).localizations.First(l => l.languageName == AlternateLocaleCode).text.text); // Assert: verify the base language string table contains the // string table entries we expect, verify the localized string // table contains the string table entries we expect System.Func <StringTableEntry, string> CompareIDs = t => t.ID; System.Func <StringTableEntry, string> CompareLocks = t => t.Lock; var tests = new[] {