0

A client wants to be able to add any language to the multilingual MVC-based site I'm currently building.

They would be responsible for providing the translations themselves and while the process doesn't need to be enabled through a GUI it needs to be simple enough, so recompiling the project is a no-go. Editing text files (possibly XMLs) is OK.

Using a semicolon-separated list of language codes in the Web.config file (for example: en-US;de-GE and so forth) and using RESX files inside the App_GlobalResources folder I am able to satisfy the conditions... at least as long as the resources are used inside the Razor pages or MVC controllers.

There is a problem, however - any attempt to use the resources in MVC view model classes (such as the Display attribute or the Compare attribute) throws an error:

System.InvalidOperationException: Cannot retrieve property 'Name' because localization failed. Type '[Resource Type Here]' is not public or does not contain a public static string property with the name '[Resource Name Here]'.

There are several questions dealing with this already on StackOverflow, but ALL of them revolve around turning the resource files from content files into embedded resources. While this might make the code function it's no good for me because the resources can no longer be edited by the client!

What else can I do in this case?

Community
  • 1
  • 1
MBender
  • 5,395
  • 1
  • 42
  • 69
  • You can let the client not edit resources, but content files, and then turn those content files into resources. – Roy Dictus Jan 28 '15 at 09:27
  • if you have layered architecture then it is hard to get such functionality as on publishing build your resx file will also be compiled and make it hard to edit dll for same. So i would suggest you to move all keyvalues to database and then move it to cache layer. – A.T. Jan 28 '15 at 09:34
  • @Aaron You really need to expand on that comment, as I have no idea what you mean... – MBender Jan 28 '15 at 09:38
  • @RoyDictus I'm not sure I follow. The idea is to have the site be multilingual AND give the client the ability to add more languages in the future. The Razor content files are, obviously, easily editable (as they are just text files), but that in no way provides a multilingual site. And while I could replace all cases of `Html.LabelFor` with `@Resources.MyResource.DisplayName`, there's still the matter of error messages or validators which are defined in the view model. – MBender Jan 28 '15 at 10:09

1 Answers1

0

In the end I scrapped using the automated mechanisms of MVC, using @Resources.MyResource.DisplayName in Razor files along with properties such as data-val-required added which can also be supplied with resources.

MBender
  • 5,395
  • 1
  • 42
  • 69