开发者

Best way to localize an entity?

I have an entity named Sta开发者_Go百科tus 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 Name values in a strongly typed Resource. 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 Name out of the appropriate resource file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜