.NET资源文件在单独的语言文件夹中
如下所示,是否可以将每个语言的单独文件夹中的资源文件放在单独的文件夹中?我希望在“ EN”文件夹中使用我的所有英语文件和“ ES”文件夹中的所有西班牙文件。我已经尝试在主资源文件夹(没有子文件夹)中使用两个文件的资源,并且可以正常工作。但是,当我像图像中的单独的“ en”和“ es”文件夹中都有文件时,即使我的浏览器设置为显示西班牙语,我也总是会获取英文文本。
我将每个资源文件的文件属性以及我用来检索值的代码
var value = Language.Resources.ResourceManager.GetString(resourceName.Trim());
CS文件包括以下ResourceManager属性的代码。第一个参数是“ clientinterface.resources.en.resources”,它总是给我英语的原因吗?
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ClientInterface.Resources.en.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
Is it possible to have resource files in separate folders for each language as shown below? I'd like all my English files in an "en" folder and all my Spanish files in an "es" folder. I have tried using the resources with both files in the main Resources folder (no subfolders), and it works correctly. However, when I have the files in separate "en" and "es" folders like in the image, I always get the English text even if my browser is set to display Spanish.
I've included file properties for each resource file along with the code I'm using to retrieve the value
var value = Language.Resources.ResourceManager.GetString(resourceName.Trim());
The auto-generated Resources.Designer.cs file includes the following code for the ResourceManager property. Is that first parameter "ClientInterface.Resources.en.Resources" the reason why it's always giving me English?
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ClientInterface.Resources.en.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到它就像您需要手动编写单个资源类,并应删除用于资源的自定义工具。
而且您需要编写自己的逻辑以接收正确的ResourceManager。
这个没有优化的小样本,但是您可以从此开始。
It's mostly because in autogenerated resource it is loading only english resource, but you need to write your logic, how to load your resource.
Example NamespaceToResources.Language.Resources
Or NamespaceToResources.Culture.Resources
In the next sample I'm loading Resource for current Culture
I see it like you need to write single Resource class manually and Custom Tool for Resources should be deleted.
And you need to write your own logic for receiving right ResourceManager.
This small sample without optimizations, but you can start with this.
It's mostly because in autogenerated resource it is loading only english resource, but you need to write your logic, how to load your resource.
Example NamespaceToResources.Language.Resources
Or NamespaceToResources.Culture.Resources
In the next sample I'm loading Resource for current Culture