.NET资源文件在单独的语言文件夹中

发布于 2025-01-22 03:30:47 字数 1448 浏览 0 评论 0原文

如下所示,是否可以将每个语言的单独文件夹中的资源文件放在单独的文件夹中?我希望在“ 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

enter image description here

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§普罗旺斯的薰衣草 2025-01-29 03:30:47

我看到它就像您需要手动编写单个资源类,并应删除用于资源的自定义工具。
而且您需要编写自己的逻辑以接收正确的ResourceManager。
这个没有优化的小样本,但是您可以从此开始。

自动生成的资源.designer.cs文件包括以下
ResourceManager属性的代码。是第一个参数
“ clientinterface.resources.en.resources”的原因
给我英语?

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

    /// <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 {
            return new global::System.Resources.ResourceManager($"ClientInterface.Resources.{Thread.CurrentThread.CurrentUICulture.Name.Replace("-", "_")}.Resource", typeof(Resource).Assembly);
        }
    }

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.

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?

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

    /// <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 {
            return new global::System.Resources.ResourceManager(
quot;ClientInterface.Resources.{Thread.CurrentThread.CurrentUICulture.Name.Replace("-", "_")}.Resource", typeof(Resource).Assembly);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文