Balanjaneyulu K
Balanjaneyulu K

Reputation: 4324

Unable to read culture specific values

I working on a localization project and unable to read the value by local from the resource file.

I have a sample solution as below:

1. Web API project
2. Resources Project.
    - In resources project, I have 3 resource files de-DE, fr-FR, and en-US.

enter image description here

I am reading the resource key "Name" from the resource file, I am able to get the value from de-DE and en-US by setting culture value as below.

[HttpGet]
    public ActionResult<IEnumerable<string>> Get()
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
        var name = Employees.Name;
        return new string[] { name };
    }

However, When I try to read the key for fr-FR local, it is giving English value. The only difference is, the French resource file is present inside a folder and others are present at project level.

Upvotes: 0

Views: 307

Answers (1)

Paul Turner
Paul Turner

Reputation: 39625

The .NET resource system is based largely on convention; it expects resource files for specific cultures to be found at very specific paths.

  • Employees.resx contains the neutral resources for the Employees container.
  • Employees.[culture].resx contains the resources for the Employees container for a specific culture.

If you have a resource file in another folder, the resource-lookup system treats it as a separate resource. fr-FR/Employees.fr-FR.resx is the French resources for the fr_FR.Employees container.

To make your resources load correctly, you just need to put them in the same folder:

  • Employees.resx
  • Employees.de-DE.resx
  • Employees.fr-FR.resx

Upvotes: 3

Related Questions