I recently figured out how to do localization in MVC using resource files containing strings. Kind of cool that MVC automatically picks the resource file for the visitor’s language. I like that!
However, how would I typically handle converting the following message into usage of a resource file?
<p>You have @ViewBag.UnreadCount unread e-mails in your inbox</p>
As you can see, ViewBag.UnreadCount is a dynamic variable that needs to be included.
What can I do?
You could use custom helpers taking parameters and use placeholders in your resource files which will be replaced with the dynamic values:
P.S. I hope that this
ViewBagthat you have shown here is only for illustration purposes and that in your actual application you are using strongly typed view models.