Question:
Although there are many localization methods, the expected functions are still impossible. The problem appears in the class library. The goal is to create the .ReSX
file, which returns the corresponding value according to the thread regional. How can we achieve this goal?Answer:
<.> 1. Add resource files:
Right -click the project "Properties", select "Add -& GT; New Items ...", and then select "Resource File" and name it "Strings.Resx". This will be used as the default resource file.<.> 2. Define string resources:
In the
<.> 3. Add system reference:
The reference to the following naming space:
System.threadingSystem.globalization
<.> 4. Code example:
In order to achieve localization of different languages, other resource documents can be created using specific language code (for example, French is "strings.fr.resx"). Add the same string resource, but use the translated value.
<.> 6. Operation CurrenTuiculture:
<code class="language-csharp">Console.WriteLine(Properties.strings.Hello);</code>
<.> 7. Return mechanism:
If you cannot find a specific regional resource file, the system will return to the default resource file or a more common resource file.
<.> 8. Fine granularity localization:
Create resource files for specific language areas (for example, French French is "Strings.fr-Fr.R.R.R.RESX"). Add resources to the unique string in this area, and the shared string can be retained in more common resource files (e.g. "Strings.fr.resx").
The above is the detailed content of How to Localize Resources in a C# Class Library Using .resx Files?. For more information, please follow other related articles on the PHP Chinese website!