Update sample to use LocalizationOptions and fixed issue in AddLocalization
This commit is contained in:
parent
eefe518ac2
commit
06aa2412a8
|
|
@ -16,7 +16,7 @@ namespace LocalizationSample
|
||||||
{
|
{
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddLocalization();
|
services.AddLocalization(options => options.ResourcesPath = "My/Resources");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IStringLocalizer<Startup> SR)
|
public void Configure(IApplicationBuilder app, IStringLocalizer<Startup> SR)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ namespace Microsoft.Framework.Localization
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The relative path under application root where resource files are located.
|
/// The relative path under application root where resource files are located.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ResourcesPath { get; set; }
|
public string ResourcesPath { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ namespace Microsoft.Framework.DependencyInjection
|
||||||
{
|
{
|
||||||
services.Configure(setupAction);
|
services.Configure(setupAction);
|
||||||
}
|
}
|
||||||
|
services.AddOptions();
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
using Microsoft.Dnx.Runtime;
|
using Microsoft.Dnx.Runtime;
|
||||||
|
|
@ -34,7 +35,8 @@ namespace Microsoft.Framework.Localization
|
||||||
_resourcesRelativePath = localizationOptions.Value.ResourcesPath ?? string.Empty;
|
_resourcesRelativePath = localizationOptions.Value.ResourcesPath ?? string.Empty;
|
||||||
if (!string.IsNullOrEmpty(_resourcesRelativePath))
|
if (!string.IsNullOrEmpty(_resourcesRelativePath))
|
||||||
{
|
{
|
||||||
_resourcesRelativePath = _resourcesRelativePath.Replace("/", ".") + ".";
|
_resourcesRelativePath = _resourcesRelativePath.Replace(Path.AltDirectorySeparatorChar, '.')
|
||||||
|
.Replace(Path.DirectorySeparatorChar, '.') + ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.Framework.Localization.Test
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var services = collection.ToList();
|
var services = collection.ToList();
|
||||||
Assert.Equal(2, services.Count);
|
Assert.Equal(3, services.Count);
|
||||||
|
|
||||||
Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType);
|
Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType);
|
||||||
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType);
|
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(IStringLocalizer<>), services[1].ServiceType);
|
||||||
Assert.Equal(typeof(StringLocalizer<>), services[1].ImplementationType);
|
Assert.Equal(typeof(StringLocalizer<>), services[1].ImplementationType);
|
||||||
Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime);
|
Assert.Equal(ServiceLifetime.Transient, services[1].Lifetime);
|
||||||
|
|
||||||
|
Assert.Equal(typeof(IOptions<>), services[2].ServiceType);
|
||||||
|
Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -43,7 +46,7 @@ namespace Microsoft.Framework.Localization.Test
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var services = collection.ToList();
|
var services = collection.ToList();
|
||||||
Assert.Equal(3, services.Count);
|
Assert.Equal(4, services.Count);
|
||||||
|
|
||||||
Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType);
|
Assert.Equal(typeof(IStringLocalizerFactory), services[0].ServiceType);
|
||||||
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType);
|
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), services[0].ImplementationType);
|
||||||
|
|
@ -55,6 +58,9 @@ namespace Microsoft.Framework.Localization.Test
|
||||||
|
|
||||||
Assert.Equal(typeof(IConfigureOptions<LocalizationOptions>), services[2].ServiceType);
|
Assert.Equal(typeof(IConfigureOptions<LocalizationOptions>), services[2].ServiceType);
|
||||||
Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime);
|
Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime);
|
||||||
|
|
||||||
|
Assert.Equal(typeof(IOptions<>), services[3].ServiceType);
|
||||||
|
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue