Update sample to use LocalizationOptions and fixed issue in AddLocalization

This commit is contained in:
Kirthi Krishnamraju 2015-09-15 16:14:57 -07:00
parent eefe518ac2
commit 06aa2412a8
10 changed files with 14 additions and 6 deletions

View File

@ -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<Startup> SR)

View File

@ -11,6 +11,6 @@ namespace Microsoft.Framework.Localization
/// <summary>
/// The relative path under application root where resource files are located.
/// </summary>
public string ResourcesPath { get; set; }
public string ResourcesPath { get; set; } = string.Empty;
}
}

View File

@ -46,7 +46,7 @@ namespace Microsoft.Framework.DependencyInjection
{
services.Configure(setupAction);
}
services.AddOptions();
return services;
}
}

View File

@ -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, '.') + ".";
}
}

View File

@ -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<LocalizationOptions>), services[2].ServiceType);
Assert.Equal(ServiceLifetime.Singleton, services[2].Lifetime);
Assert.Equal(typeof(IOptions<>), services[3].ServiceType);
Assert.Equal(ServiceLifetime.Singleton, services[3].Lifetime);
}
}
}