I am using database with multiple language support. Now the problem is that I need to enter my language into query in order to get information and it is fine, but what would be optimal way to store that information.
On client side it will be stored in cookies, of course. Now only way I can think of is making global variable on class and then use it in my functions. Is that only way?
Example code
private string lang = Infrastructure.UserSettings.Language(); // I don't have this implemented yet
[HttpGet]
public dynamic List()
{
string lang = "English"; // That's why I set it here manually for testing
var items = _db.Items.OrderByDescending(x => x.ID).Select(x => new
{
ID = x.ID,
Price = x.Price,
Name = x.ItemTranslations.Where(y => y.Language.Name == lang).Select(y => y.Name).SingleOrDefault(),
Category = new {
ID = x.Category.ID,
Name = x.Category.CategoryTranslations.Where(y => y.Language.Name == lang).Select(y => y.Name).SingleOrDefault()
}
});
return items;
}
My question: Is this good way of doing this or there is some more optimal way?