Developing applications for global users need to be able to localize content according to different languages and culture. In C#, localization can be achieved by using resources (.Resx) files.
Create resource files
To add resource files to the project, please perform the following operations:
Right -click the project in the solution resource manager.
To access resources from the code, please perform the following operations:
Add references to System.threading and System.globalization.Use the following code to retrieve localized string:
Console.WriteLine(Properties.strings.Hello);
This will make applications use French (France) regional resources.
<退> Retreatment mechanism
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("fr-FR");
C#provides a refund mechanism to ensure that localized resources can always be used:
If you can't find a specified regional resource file, it will return to regional characteristics with the same language (for example, "FR" rather than "FR-FR").
If you can't find any specific regional or language resource files, it will return to the default resource file (no language code).
Strings.fr-fr.resx (French French) Strings.fr-Ca.Resx (French in Canada)
Summary
The above is the detailed content of How Can I Localize My C# Application Using Resource Files?. For more information, please follow other related articles on the PHP Chinese website!