public static LocalizationDictionary Create(ILocalizationResolver resolver, CultureInfo culture, TimeZoneInfo timeZone) { string cultureName = culture?.Name; string data = resolver.ResolveCulture(cultureName).ToString(); var strings = JsonHelper.DeserializeAndFlatten(data).Select(o => new LocalizedString(cultureName, o.Key, o.Value.ToString())); return(new LocalizationDictionary(strings.ToDictionary(o => o.Name, o => o as ILocalizedString)) { Culture = culture, TimeZone = timeZone }); }
/// <summary> /// Initializes the providers (Content Provider, Link Resolver, Media Helper, etc.) using dependency injection, i.e. obtained from configuration. /// </summary> /// <param name="dependencyResolver">A delegate that provide an implementation instance for a given interface type.</param> /// <remarks> /// This method took a parameter of type <see cref="System.Web.Mvc.IDependencyResolver"/> in DXA 1.1 and 1.2. /// That created an undesirable dependency on System.Web.Mvc and therefore this has been changed to a delegate in DXA 1.3. /// We couldn't keep the old signature (as deprecated) because that would still result in a dependency on System.Web.Mvc. /// This means that the call in Global.asax.cs must be changed from /// <c>SiteConfiguration.InitializeProviders(DependencyResolver.Current);</c> to /// <c>SiteConfiguration.InitializeProviders(DependencyResolver.Current.GetService);</c> /// </remarks> public static void InitializeProviders(Func <Type, object> dependencyResolver) { using (new Tracer()) { ContentProvider = GetProvider <IContentProvider>(dependencyResolver); NavigationProvider = GetProvider <INavigationProvider>(dependencyResolver); ContextClaimsProvider = GetProvider <IContextClaimsProvider>(dependencyResolver); LinkResolver = GetProvider <ILinkResolver>(dependencyResolver); RichTextProcessor = GetProvider <IRichTextProcessor>(dependencyResolver); ConditionalEntityEvaluator = GetProvider <IConditionalEntityEvaluator>(dependencyResolver, isOptional: true); MediaHelper = GetProvider <IMediaHelper>(dependencyResolver); LocalizationResolver = GetProvider <ILocalizationResolver>(dependencyResolver); #pragma warning disable 618 StaticFileManager = GetProvider <IStaticFileManager>(dependencyResolver, isOptional: true); #pragma warning restore 618 } }
public LocalizeResponsePipeline(ILocalizationResolver localizationResolver) { this.localizationResolver = localizationResolver; }
public LocalizationService(ILocalizationResolver resolver) { this.resolver = resolver; }
private void Load() { using (new Tracer(this)) { lock (_loadLock) { // NOTE: intentionally setting LastRefresh first, because while loading other classes (e.g. BinaryFileManager) may be using LastRefresh to detect stale content. LastRefresh = DateTime.Now; IsHtmlDesignPublished = true; List <string> mediaPatterns = new List <string>(); string versionUrl = System.IO.Path.Combine(Path.ToCombinePath(true), @"version.json").Replace("\\", "/"); string versionJson = SiteConfiguration.ContentProvider.GetStaticContentItem(versionUrl, this).GetText(); if (versionJson == null) { //it may be that the version json file is 'unmanaged', ie just placed on the filesystem manually //in which case we try to load it directly - the HTML Design is thus not published from CMS string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SiteConfiguration.SystemFolder, @"assets\version.json"); if (File.Exists(path)) { versionJson = File.ReadAllText(path); IsHtmlDesignPublished = false; } } if (versionJson != null) { Version = Json.Decode(versionJson).version; } dynamic bootstrapJson = GetConfigBootstrapJson(); if (bootstrapJson != null) { //The _all.json file contains a reference to all other configuration files if (bootstrapJson.defaultLocalization != null && bootstrapJson.defaultLocalization) { IsDefaultLocalization = true; } if (bootstrapJson.staging != null && bootstrapJson.staging) { IsStaging = true; } if (bootstrapJson.mediaRoot != null) { string mediaRoot = bootstrapJson.mediaRoot; if (!mediaRoot.EndsWith("/")) { mediaRoot += "/"; } mediaPatterns.Add(String.Format("^{0}{1}.*", mediaRoot, mediaRoot.EndsWith("/") ? String.Empty : "/")); } if (bootstrapJson.siteLocalizations != null) { ILocalizationResolver localizationResolver = SiteConfiguration.LocalizationResolver; SiteLocalizations = new List <Localization>(); foreach (dynamic item in bootstrapJson.siteLocalizations) { string localizationId = item.id ?? item; try { Localization siteLocalization = localizationResolver.GetLocalization(localizationId); siteLocalization.IsDefaultLocalization = item.isMaster ?? false; SiteLocalizations.Add(siteLocalization); } catch (DxaUnknownLocalizationException) { Log.Error("Unknown localization ID '{0}' specified in SiteLocalizations for Localization [{1}].", localizationId, this); } } } if (IsHtmlDesignPublished) { mediaPatterns.Add("^/favicon.ico"); mediaPatterns.Add(String.Format("^{0}/{1}/assets/.*", Path, SiteConfiguration.SystemFolder)); } if (bootstrapJson.files != null) { List <string> configFiles = new List <string>(); foreach (string file in bootstrapJson.files) { configFiles.Add(file); } LoadConfig(configFiles); } mediaPatterns.Add(String.Format("^{0}/{1}/.*\\.json$", Path, SiteConfiguration.SystemFolder)); } StaticContentUrlPattern = String.Join("|", mediaPatterns); _staticContentUrlRegex = new Regex(StaticContentUrlPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); Culture = GetConfigValue("core.culture"); Language = GetConfigValue("core.language"); string formats = GetConfigValue("core.dataFormats"); DataFormats = formats == null ? new List <string>() : formats.Split(',').Select(f => f.Trim()).ToList(); } } }
protected LocalizationResolverTest(ILocalizationResolver testLocalizationResolver) { _testLocalizationResolver = testLocalizationResolver; }
protected virtual void Load() { using (new Tracer(this)) { lock (_loadLock) { // NOTE: intentionally setting LastRefresh first, because while loading other classes (e.g. BinaryFileManager) may be using LastRefresh to detect stale content. LastRefresh = DateTime.Now; List <string> mediaPatterns = new List <string>(); VersionData versionData = null; try { LoadStaticContentItem("/version.json", ref versionData); IsHtmlDesignPublished = true; } catch (DxaItemNotFoundException) { //it may be that the version json file is 'unmanaged', ie just placed on the filesystem manually //in which case we try to load it directly - the HTML Design is thus not published from CMS IsHtmlDesignPublished = false; string versionJsonPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SiteConfiguration.SystemFolder, @"assets\version.json"); if (File.Exists(versionJsonPath)) { string versionJson = File.ReadAllText(versionJsonPath); versionData = JsonConvert.DeserializeObject <VersionData>(versionJson); Log.Info("Obtained '{0}' directly from file system.", versionJsonPath); } else { Log.Warn("HTML design is not published nor does file '{0}' exist on disk. Setting version to v0.0", versionJsonPath); versionData = new VersionData { Version = "v0.0" }; } } Version = versionData.Version; LocalizationData localizationData = null; try { LoadStaticContentItem("config/_all.json", ref localizationData); IsDefaultLocalization = localizationData.IsDefaultLocalization; IsXpmEnabled = localizationData.IsXpmEnabled; if (localizationData.MediaRoot != null) { string mediaRoot = localizationData.MediaRoot; if (!mediaRoot.StartsWith("/")) { // SDL Web 8 context-relative URL mediaRoot = $"{Path}/{mediaRoot}"; } if (!mediaRoot.EndsWith("/")) { mediaRoot += "/"; } mediaPatterns.Add($"^{mediaRoot}.*"); } if (localizationData.SiteLocalizations != null) { ILocalizationResolver localizationResolver = SiteConfiguration.LocalizationResolver; SiteLocalizations = new List <ILocalization>(); foreach (SiteLocalizationData siteLocalizationData in localizationData.SiteLocalizations) { try { ILocalization siteLocalization = localizationResolver.GetLocalization(siteLocalizationData.Id); if (siteLocalization.LastRefresh == DateTime.MinValue) { // Localization is not fully initialized yet; partially initialize it using the Site Localization Data. siteLocalization.Id = siteLocalizationData.Id; siteLocalization.Path = siteLocalizationData.Path; siteLocalization.IsDefaultLocalization = siteLocalizationData.IsMaster; siteLocalization.Language = siteLocalizationData.Language; } SiteLocalizations.Add(siteLocalization); } catch (DxaUnknownLocalizationException) { Log.Error("Unknown localization ID '{0}' specified in SiteLocalizations for Localization [{1}].", siteLocalizationData.Id, this); } } } } catch (DxaItemNotFoundException) { Log.Warn("HTML design is not published nor does file 'config/_all.json' exist on disk."); } if (IsHtmlDesignPublished) { mediaPatterns.Add("^/favicon.ico"); mediaPatterns.Add($"^{Path}/{SiteConfiguration.SystemFolder}/assets/.*"); } mediaPatterns.Add($"^{Path}/{SiteConfiguration.SystemFolder}/.*\\.json$"); StaticContentUrlPattern = String.Join("|", mediaPatterns); _staticContentUrlRegex = new Regex(StaticContentUrlPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled); try { Culture = GetConfigValue("core.culture"); Language = GetConfigValue("core.language"); string formats = GetConfigValue("core.dataFormats"); DataFormats = formats?.Split(',').Select(f => f.Trim()).ToList() ?? new List <string>(); } catch (Exception e) { Log.Warn(e.Message); } } } }
public static LocalizationDictionary Create(ILocalizationResolver resolver, string cultureName, string timeZoneId) { return(Create(resolver, CultureInfo.GetCultureInfo(cultureName), TimeZoneInfo.FindSystemTimeZoneById(timeZoneId))); }