public static TranslationsComposite GetAllTranslationsForLocale(HttpRequestMessage Request, string id) { IDictionary <string, object> env = Request.GetOwinEnvironment(); var options = new LocaleOptions { LocaleProvider = e => { return(id); } }; var localeService = new GlobalizedLocalizationService(new OwinEnvironmentService(env), options); var allTranslationsForLocale = (from eventId in AllEventIds let value = localeService.GetString(Eventscategory, eventId) select new IdTranslation { Id = eventId, Value = value }).ToList(); allTranslationsForLocale.AddRange(from messageId in AllMessageIds let value = localeService.GetString(Messagescategory, messageId) select new IdTranslation { Id = messageId, Value = value }); allTranslationsForLocale.AddRange(from scopeId in AllScopeIds let value = localeService.GetString(ScopesCategory, scopeId) select new IdTranslation { Id = scopeId, Value = value }); var headerValue = Request.Headers.AcceptLanguage.OrderByDescending(s => s.Quality.GetValueOrDefault(1)); var localeFromHeader = headerValue.FirstOrDefault(); return(new TranslationsComposite { Locale = id, HeaderLanguage = localeFromHeader.Value, Translations = allTranslationsForLocale, IdSrvVersion = VersionHelper.GetIdsrvVersion() }); }
private static void AssertTranslationExists(string culture, IEnumerable <string> ids, string category) { var options = new LocaleOptions { Locale = culture }; var service = new GlobalizedLocalizationService(options); var notFoundTranslations = new List <string>(); foreach (var id in ids) { var localizedString = service.GetString(category, id); if (string.IsNullOrEmpty(localizedString)) { var errormsg = string.Format("Could not find translation of Id '{0}' in {1}", id, string.IsNullOrEmpty(culture) ? "IdentityServers internals" : culture); notFoundTranslations.Add(errormsg); } else { string message = string.Format("{0} - {1}:{2} - {3}", culture, category, id, localizedString); Trace.WriteLine(message); Debug.WriteLine(message); Console.WriteLine(message); Assert.NotEqual("", localizedString.Trim()); } } if (notFoundTranslations.Any()) { var concated = notFoundTranslations.Aggregate((x, y) => x + ", " + y); throw new AssertActualExpectedException("Some translation", "NOTHING!", concated); } }
public void ContainsEnglishLocalesAsWell(string locale) { var env = new Dictionary <string, object>(); var options = new LocaleOptions { LocaleProvider = e => locale }; var global = new GlobalizedLocalizationService(new OwinEnvironmentService(env), options); var resource = global.GetString(IdSrvConstants.Messages, MessageIds.MissingClientId); Assert.Equal("client_id is missing", resource); }
public void FetchesResourceWhenUsingLocaleProviderFunc() { var options = new LocaleOptions { LocaleProvider = env => "nb-NO" }; var envServiceMock = new Fake <OwinEnvironmentService>().FakedObject; var service = new GlobalizedLocalizationService(envServiceMock, options); var norwegianString = service.GetString(IdSrvConstants.Messages, MessageIds.MissingClientId); Assert.Equal("ClientId mangler", norwegianString); }
public void UsesFallbackWhenIsSet() { const string someid = "SomeId"; var mock = new Fake <ILocalizationService>(); mock.CallsTo(loc => loc.GetString(IdSrvConstants.Messages, someid)).Returns("fallbackValue"); var service = new GlobalizedLocalizationService(new LocaleOptions { Locale = "nb-NO", FallbackLocalizationService = mock.FakedObject }); var result = service.GetString(IdSrvConstants.Messages, someid); Assert.Equal("fallbackValue", result); }
public void UnknownLocalesUseDefaultLocale(string locale) { var options = new LocaleOptions { LocaleProvider = env => locale }; var envServiceMock = new Fake <OwinEnvironmentService>().FakedObject; var service = new GlobalizedLocalizationService(envServiceMock, options); var resource = service.GetString(IdSrvConstants.Messages, MessageIds.MissingClientId); Assert.Equal("client_id is missing", resource); }
public void FetchesResrouceBasedOnOwinEnvironment() { IDictionary <string, object> environment = new Dictionary <string, object>(); environment["UserSettings.Language"] = "nb-NO"; var owinEnvironmentService = new OwinEnvironmentService(environment); var options = new LocaleOptions { LocaleProvider = env => env["UserSettings.Language"].ToString() }; var service = new GlobalizedLocalizationService(owinEnvironmentService, options); var norwegianString = service.GetString(IdSrvConstants.Messages, MessageIds.MissingClientId); Assert.Equal("ClientId mangler", norwegianString); }