/// <summary> /// Add a new language into the system (does NOT set current language) /// </summary> /// <param name="language"></param> public void Add(Language language) { // Does the language already exist by name or language-locale? var existingLanguage = GetLanguageByLanguageCulture(language.LanguageCulture); if (existingLanguage != null) { throw new LanguageOrCultureAlreadyExistsException(string.Format("There is already a language defined for language-culture '{0}'", existingLanguage.LanguageCulture)); } // Make sure that the new language has a set of empty resources language.LocaleStringResources = new List <LocaleStringResource>(); foreach (var localeResourceKey in _localizationRepository.GetAllResourceKeys()) { var localeStringResource = new LocaleStringResource { Language = language, LocaleResourceKey = localeResourceKey, ResourceValue = string.Empty }; language.LocaleStringResources.Add(localeStringResource); } language = SanitizeLanguage(language); _localizationRepository.Add(language); }
public void ImportLanguage() { // Ensure language does not exist _localizationRepositorySub.GetLanguageByLanguageCulture(Arg.Any <string>()).Returns(x => null); var resourceKey1 = new LocaleResourceKey { DateAdded = DateTime.UtcNow, Id = Guid.NewGuid(), Name = "testKey1", Notes = "test notes" }; var resourceValue1 = new LocaleStringResource { LocaleResourceKey = resourceKey1, ResourceValue = "testValue1" }; var resourceKey2 = new LocaleResourceKey { DateAdded = DateTime.UtcNow, Id = Guid.NewGuid(), Name = "testKey2", Notes = "test notes" }; var resourceValue2 = new LocaleStringResource { LocaleResourceKey = resourceKey1, ResourceValue = "testValue2" }; var newLanguage = new Language { LanguageCulture = "fr-FR", Name = "French", LocaleStringResources = new List <LocaleStringResource> { resourceValue1, resourceValue2 }, }; _localizationRepositorySub.GetAllResourceKeys().Returns(new List <LocaleResourceKey> { resourceKey1, resourceKey2 }); _localizationRepositorySub.GetResourceKey("testKey1").Returns(resourceKey1); _localizationRepositorySub.GetResourceKey("testKey2").Returns(resourceKey2); _localizationRepositorySub.GetResourceKey("testKeyNew").Returns(x => null); _localizationRepositorySub.GetAll().Returns(new List <Language> { newLanguage }); var testData = new List <string> { "testKey1,testValue1", "testKey2,testValue2", ",should not import", // Test for ignore of empty key "testKeyNew,testValueNew" }; var report = _localizationService.FromCsv("fr-FR", testData); Assert.AreEqual(report.Warnings.Count, 1); Assert.AreEqual(report.Warnings[0].ErrorWarningType, CsvErrorWarningType.NewKeyCreated); Assert.AreEqual(report.Errors.Count, 0); }