I have an entity named Status where I store different status. I have two properties for this entity: IdStatus and Name.
This entity is filled like this:
IdStatus: 1 - Name: Open
IdStatus: 2 - Name: Closed
IdStatus: 3 - Name: Deleted
I retrieve my status like this:
[HttpGet]
private void RetrieveMyStatus(MyViewModel model)
{
var sta = entities.Status.Select(o => new SelectListItem { Text = o.Name, Value = o.IdStatus.ToString() }).ToList();
model.Status = sta;
}
As you can see, until now, I manage only english. But now, I would like to manage french also.
I think I had to adapt my entity like this:
IdStatus: 1 - NameEN: Open - NameFR: Ouvert
IdStatus: 2 - NameEN: Closed - NameFR: Fermé
IdStatus: 3 - NameEN: Deleted - NameFR: Supprimé
How can I adapt my function RetrieveMyStatus in order to get the french or english Name property depending of the culture of the user? (stored in sessionWrapper.Culture) I don’t figure out what is the best way?
Thank you for your help.
Put the
Namevalues in a strongly typedResource. Then define a resx file for the other localized resources you may need to serve up. For example, you would have a default and this would be in Resources.resx. If you also need to serve French resources too then create a Resources.fr.resx file with the French strings in (the keys need to be the same in both)This will then use the Current UICulture of the Request to get the
Nameout of the appropriate resource file.