找到你要的答案

Q:How to deal with multiple resource files for localization?

Q:如何处理多个本地化的资源文件?

I have a Project in which lot of resource strings are used. So, I keep them organized based on modules as a folder structure.

Like if Module A is a folder then under Module A i have the following files.

Module A

       ResourceFileA1.resx 
       ResourceFileA2.resx
       ResourceFileA1.de-DE.resx
       ResourceFileA2.de-DE.resx

and similar is the structure for module B.

But I just want to have a single class file or If not possible single wrapper class (for multiple classes pertaining to each resource file) to get the resource string. I am trying something like GetString(moduleA.ResourceFileA1.String)

I have tried something that is explained here But could not get it right. Can anyone please help?

Thanks in advance,

我有一个项目,其中使用了大量的资源字符串。所以,我让他们组织基于模块作为文件夹结构。

就像模块A是一个文件夹那么模块A下面我有以下文件。

Module A

       ResourceFileA1.resx 
       ResourceFileA2.resx
       ResourceFileA1.de-DE.resx
       ResourceFileA2.de-DE.resx

和类似的是模块B的结构。

但我只是希望有一个单独的类文件或不可能的单个包装类(对于每个资源文件的多个类)以获取资源字符串。我试着像GetString(模块。resourcefilea1。字符串)

我尝试了一些解释,但不能得到它的权利。有谁能帮忙吗?

先谢谢了。

answer1: 回答1:

You did not mention which version of the .NET framework you are restricted to, but assuming you are on at least .NET 2.0, you really shouldn't need to worry about manually managing your resource files. Add a new resource file through Visual Studio, and you should see an auto-generated

ResourceFileA1.resx

and

ResourceFileA1.Designer.cs

The designer file should automatically create for you a compile-time reference to any resource items you put in your file such as:

moduleA.ResourceFileA1.YourStringKey

When you add new locales (.de-DE.resx, etc), moduleA.ResourceFileA1.YourStringKey should automatically refer to the right resource file based on Thread.CurrentCulture, however if you want you can pass it in explicitly by calling GetString

你没有提到限制你的.NET框架,但是假设你至少在.NET 2上,你真的不需要担心手工管理你的资源文件。通过VisualStudio添加一个新的资源文件,您将看到一个自动生成的文件

ResourceFileA1.resx

ResourceFileA1.Designer.cs

设计器文件将自动为您创建一个编译时引用,将您放置在文件中的任何资源项(例如:

moduleA.ResourceFileA1.YourStringKey

当你添加新的地点(。de-de.resx,等),modulea.resourcefilea1.yourstringkey应该自动是指基于thread.currentculture正确的资源文件,但是如果你想你可以通过它在显式的调用getString

answer2: 回答2:

The files you are showing are all local resources, designed to be accessible only by certain sections of your app. But you can also create global resources that can be used by all of your application's code. Assuming your app is an ASP.NET app these resources are in App_GlobalResources. See this MSDN page , particularly the sub-sections "Global Resource Files" and "Local Resource Files".

The files you are showing are all local resources, designed to be accessible only by certain sections of your app. But you can also create global resources that can be used by all of your application's code. Assuming your app is an ASP.NET app these resources are in App_GlobalResources. See this MSDN page , particularly the sub-sections "Global Resource Files" 和 "Local Resource Files".

answer3: 回答3:

Here is the code below.

 [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
    public static global::System.Resources.ResourceManager ResourceManager
    {

        get
        {
            resourceMan = new global::System.Resources.ResourceManager("Ral." + Ral.ResourceFolderPath.GetClientKey + ".Asset.Resource", typeof(Resource).Assembly);
            return resourceMan;
        }
    }

下面是下面的代码。

 [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
    public static global::System.Resources.ResourceManager ResourceManager
    {

        get
        {
            resourceMan = new global::System.Resources.ResourceManager("Ral." + Ral.ResourceFolderPath.GetClientKey + ".Asset.Resource", typeof(Resource).Assembly);
            return resourceMan;
        }
    }
answer4: 回答4:

MSDN link works for me, since i was not following the Naming convention of resx files. http://msdn.microsoft.com/en-us/library/ms227427%28v=vs.100%29.aspx

it says "When you create resource files, you start by creating a base .resx file. For each language that you want to support, create a new file that has the same file name. But in the name, include the language or the language and culture (culture name). For a list of culture names, see the CultureInfo class. For example, you might create the following files:

WebResources.resx
The base resource file. This is the default (fallback) resource file.
WebResources.es.resx
A resource file for Spanish.
WebResources.es-mx.resx
A resource file for Spanish (Mexico) specifically.
WebResources.de.resx
A resource file for German."

MSDN link works for me, since i was not following the Naming convention of resx files. http://msdn.microsoft.com/en-us/library/ms227427%28v=vs.100%29.aspx

it says "When you create resource files, you start by creating a base .resx file. For each language that you want to support, create a new file that has the same file name. But in the name, include the language or the language 和 culture (culture name). For a list of culture names, see the CultureInfo class. For example, you might create the following files:

WebResources.resx
The base resource file. This is the default (fallback) resource file.
WebResources.es.resx
A resource file for Spanish.
WebResources.es-mx.resx
A resource file for Spanish (Mexico) specifically.
WebResources.de.resx
A resource file for German."

c#  localization  resource-files  satellite-assembly