I need to implement localization for resource (.resx) messages in a MVC application, but have been failing to do so.
Reviewing the steps I am following:
1. Create a Localization project and add as many resource (.resx) files as the languages you need to support. Add the messages you want to display, in all the chosen languages. Select "Public" at Visual Studio's "access modifier" option. Make sure you name the resource files according to the required convention, i.e., MyResource.resx for the default language, MyResource-fr.resx for french localization, MyResource.ro for romanian localization, an so forth.
2. Detect and parse the Accept-Language http header from the http request. Pick the one with the highest 'q' factor, whenever present. If none is present or all q values are the same, pick the 1st language accepted.
(Update: I just learned (see @Zealous comment) that adding <globalization enableClientBasedCulture="true" culture="auto" uiCulture="auto"/>
to web.config will do exactly the same, so no need for the manual work).
3. Make the application controllers inherit from a base controller (could have been done via filter as well) that changes the references of Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture to new instances created on the fly, according to the most preferred language accepted, as extracted from the preceeding step.
4. Add a reference to the Localization project created in the step above to the one that needs to reference the messages. Upon referencing a message, simply refer to the resource default file name 'dot' the message you want to display. In our example, it would be MyResource.Welcome.
Expected results: upon sending http requests set with Accept-Language to 'fr', receive a response with "Bienvenue", whereas when seting Accept-Language to 'en' (or adding several languages and playing with the q factor), receive a response with "Welcome".
Somehow my responses are always using the default resource file (in this case, English).
What am I missing or am doing wrong?