diff --git a/samples/LocalizationSample/Startup.es-ES.resx b/samples/LocalizationSample/My/Resources/Startup.es-ES.resx similarity index 100% rename from samples/LocalizationSample/Startup.es-ES.resx rename to samples/LocalizationSample/My/Resources/Startup.es-ES.resx diff --git a/samples/LocalizationSample/Startup.fr-FR.resx b/samples/LocalizationSample/My/Resources/Startup.fr-FR.resx similarity index 100% rename from samples/LocalizationSample/Startup.fr-FR.resx rename to samples/LocalizationSample/My/Resources/Startup.fr-FR.resx diff --git a/samples/LocalizationSample/Startup.ja-JP.resx b/samples/LocalizationSample/My/Resources/Startup.ja-JP.resx similarity index 100% rename from samples/LocalizationSample/Startup.ja-JP.resx rename to samples/LocalizationSample/My/Resources/Startup.ja-JP.resx diff --git a/samples/LocalizationSample/Startup.zh-CN.resx b/samples/LocalizationSample/My/Resources/Startup.zh-CN.resx similarity index 100% rename from samples/LocalizationSample/Startup.zh-CN.resx rename to samples/LocalizationSample/My/Resources/Startup.zh-CN.resx diff --git a/samples/LocalizationSample/Startup.zh.resx b/samples/LocalizationSample/My/Resources/Startup.zh.resx similarity index 100% rename from samples/LocalizationSample/Startup.zh.resx rename to samples/LocalizationSample/My/Resources/Startup.zh.resx diff --git a/samples/LocalizationSample/Startup.cs b/samples/LocalizationSample/Startup.cs index 384c0c7f0f..265ddce62c 100644 --- a/samples/LocalizationSample/Startup.cs +++ b/samples/LocalizationSample/Startup.cs @@ -16,7 +16,7 @@ namespace LocalizationSample { public void ConfigureServices(IServiceCollection services) { - services.AddLocalization(); + services.AddLocalization(options => options.ResourcesPath = "My/Resources"); } public void Configure(IApplicationBuilder app, IStringLocalizer SR) diff --git a/src/Microsoft.Framework.Localization/LocalizationOptions.cs b/src/Microsoft.Framework.Localization/LocalizationOptions.cs index f1da826d83..211e9622a4 100644 --- a/src/Microsoft.Framework.Localization/LocalizationOptions.cs +++ b/src/Microsoft.Framework.Localization/LocalizationOptions.cs @@ -11,6 +11,6 @@ namespace Microsoft.Framework.Localization /// /// The relative path under application root where resource files are located. /// - public string ResourcesPath { get; set; } + public string ResourcesPath { get; set; } = string.Empty; } } diff --git a/src/Microsoft.Framework.Localization/LocalizationServiceCollectionExtensions.cs b/src/Microsoft.Framework.Localization/LocalizationServiceCollectionExtensions.cs index 543a985cda..6b6f86d866 100644 --- a/src/Microsoft.Framework.Localization/LocalizationServiceCollectionExtensions.cs +++ b/src/Microsoft.Framework.Localization/LocalizationServiceCollectionExtensions.cs @@ -46,7 +46,7 @@ namespace Microsoft.Framework.DependencyInjection { services.Configure(setupAction); } - + services.AddOptions(); return services; } } diff --git a/src/Microsoft.Framework.Localization/ResourceManagerStringLocalizerFactory.cs b/src/Microsoft.Framework.Localization/ResourceManagerStringLocalizerFactory.cs index 49c7d12c56..b299823b26 100644 --- a/src/Microsoft.Framework.Localization/ResourceManagerStringLocalizerFactory.cs +++ b/src/Microsoft.Framework.Localization/ResourceManagerStringLocalizerFactory.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.IO; using System.Reflection; using System.Resources; using Microsoft.Dnx.Runtime; @@ -34,7 +35,8 @@ namespace Microsoft.Framework.Localization _resourcesRelativePath = localizationOptions.Value.ResourcesPath ?? string.Empty; if (!string.IsNullOrEmpty(_resourcesRelativePath)) { - _resourcesRelativePath = _resourcesRelativePath.Replace("/", ".") + "."; + _resourcesRelativePath = _resourcesRelativePath.Replace(Path.AltDirectorySeparatorChar, '.') + .Replace(Path.DirectorySeparatorChar, '.') + "."; } } diff --git a/test/Microsoft.Framework.Localization.Tests/LocalizationServiceCollectionExtensionsTest.cs b/test/Microsoft.Framework.Localization.Tests/LocalizationServiceCollectionExtensionsTest.cs index 213077e992..c8b10bc8b4 100644 --- a/test/Microsoft.Framework.Localization.Tests/LocalizationServiceCollectionExtensionsTest.cs +++ b/test/Microsoft.Framework.Localization.Tests/LocalizationServiceCollectionExtensionsTest.cs @@ -21,7 +21,7 @@ namespace Microsoft.Framework.Localization.Test // Assert var services = collection.ToList(); - Assert.Equal(2, services.Count); + Assert.Equal(3, services.Count); Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType); Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType); @@ -30,6 +30,9 @@ namespace Microsoft.Framework.Localization.Test Assert.Equal(typeof(IStringLocalizer<>), services[1].ServiceType); Assert.Equal(typeof(StringLocalizer<>), services[1].ImplementationType); Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime); + + Assert.Equal(typeof(IOptions<>), services[2].ServiceType); + Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime); } [Fact] @@ -43,7 +46,7 @@ namespace Microsoft.Framework.Localization.Test // Assert var services = collection.ToList(); - Assert.Equal(3, services.Count); + Assert.Equal(4, services.Count); Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType); Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType); @@ -55,6 +58,9 @@ namespace Microsoft.Framework.Localization.Test Assert.Equal(typeof(IConfigureOptions), services[2].ServiceType); Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime); + + Assert.Equal(typeof(IOptions<>), services[3].ServiceType); + Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime); } } }