Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manual creation of strings resource file not working with Application

I am working on a project where localised strings are to be inserted later into the live ASP.NET (MVC4) site/application. The way we plan to achieve this (for validation messages etc.) is to obtain the strings from the clients, put them in a .resx file, compile this .resx file into a .resources file and then into a .dll. Finally this .dll is placed in the relevant language folder on the live site. However, this manually created .dll is not being picked up by the application. Instead it falls back to the default language .dll. On the other hand if the .resx file was compiled via Visual Studio (2012) then the .dll is happily picked up by the application, and it displays the localised text from it.

I am guessing the issue lies in the way I create the .dll manually, although I can't find anything wrong with it. Here's what I run in the command-line console:

resgen Strings.fr-FR.resx Strings.fr-FR.resources

then,

al /t:lib /culture:fr-FR /embed:Strings.fr-FR.resources /out:MyApplication.resources.dll
like image 834
Hashim Akhtar Avatar asked Nov 13 '12 12:11

Hashim Akhtar


People also ask

How do I get .resx file strings in asp net core?

Create a folder in whatever project you want to store the resx files in - default, call it "Resources". Create a new resx file with the specific culture and the file name you'll look up later: If you had a shared one, you could do: SharedResource. en-US. resx.


1 Answers

It might be because of the namespace used in the French-localized resource DLL when you are generating it which is different from the namespace used by your application for the resource files.

You have to rename your resource file from Strings.fr-FR.resources to MyApplication.Namespace.Where.My.Resource.Files.Are.Located.Resources.fr-FR.resources.

By default, resource files are located in the Properties folder. It means you can access a localized string using the fully qualified name MyApplication.Properties.Resources.MyString.

If your application is named MyApplication and your resource files are located under the Properties folder, generate your resources file this way:

resgen Strings.fr-FR.resx MyApplication.Properties.Resources.fr-FR.resources

Then generate the DLL this way:

al /t:lib /Culture:fr-FR /embed:MyApplication.Properties.Resources.fr-FR.resources /out:MyApplication.resources.dll

Now when you put it in your fr-FR folder in the bin folder of your application, it should be recognized.

Take a look to the manifest of the assembly you previously generated and the one which is now generated using ildasm.exe. You will see in the second case you have the following line .mresource public 'MyApplication.Properties.Resources.fr-FR.resources' when in the first case it should be something like that .mresource public 'Strings.fr-FR.resources'. Since your application looks for the localized strings into the namespace 'MyApplication.Properties', it couldn't find it... Of course, adapt 'MyApplication.Properties.Resources' to whatever is used in your application (maybe 'MyApplication.Localization.Strings').

like image 194
Guillaume Avatar answered Nov 09 '22 19:11

Guillaume