You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MaterialTraceabilityUI.Resources
|
|
|
|
|
|
{
|
|
|
|
|
|
public interface IResource
|
|
|
|
|
|
{
|
|
|
|
|
|
string GetString(string name);
|
|
|
|
|
|
CultureInfo CurrentCulture { set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
public class Resource : IResource
|
|
|
|
|
|
{
|
|
|
|
|
|
private ResourceManager stringResource;
|
|
|
|
|
|
//我们这样设置的时候ResourceManager会去查找MultilanguageTest.StringResource.en-us.resx,如果没有会查找MultilanguageTest.StringResource.resx
|
|
|
|
|
|
private CultureInfo culture = new CultureInfo("zh-cn"); //默认值
|
|
|
|
|
|
public Resource()
|
|
|
|
|
|
{
|
|
|
|
|
|
//MultilanguageTest.StringResource是根名称,该实例使用指定的System.Reflection.Assmbly查找从指定的跟名称导出的文件中包含的资源
|
|
|
|
|
|
//此处注意WpfApp2.Resources.Lang,Lang是资源文件的名字
|
|
|
|
|
|
stringResource = new ResourceManager("MaterialTraceabilityUI.Resources.Lang", typeof(Resource).Assembly);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 通过资源名称获取资源内容
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public string GetString(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return stringResource.GetString(name, culture);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 改变当前的区域信息,ResourceManager可以通过当前区域信息去查找.resx文件
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public CultureInfo CurrentCulture
|
|
|
|
|
|
{
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
culture = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|