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

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').

链接地址: http://www.djcxy.com/p/11434.html

上一篇: java.lang.NoSuchMethodError:javax.xml.ws.WebFault.messageName

下一篇: 手动创建不适用于应用程序的字符串资源文件