JamaicanMeCrazy
JamaicanMeCrazy

Reputation: 53

Resource File lookup with variable

Project type: C# Mvc 4

Hi all I was wondering if anyone with experience in Resource files can help me:

I have a basic setup for string localization so I have created resource files for different cultures and they work fine, i.e. In the view if you put:

@Resources.Title

It successfully looks up the string with the key title in the resource file respective to the active culture on your browser.

The question I have is if it is possible to do the lookup dynamically e.g.:

@Resources.Model.Title where Model.Title is a variable known at runtime

Thanks in advance

Upvotes: 2

Views: 2610

Answers (1)

Christoph Fink
Christoph Fink

Reputation: 23093

You can use the following:

@Resources.ResourceManager.GetString(Model.Title)

There is also an overload where you can supply a CultureInfo to get the string in a different language then the current one. Otherwise the culture from the Thread.CurrentThread.CurrentUICulture is used.

Upvotes: 3

Related Questions