KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I know this matter has already been brought on these pages many times, but still I haven't found the "good solution" I am required to find. Let's start the explanation. Localization in .net, and in mvc, is made in 2 ways that can even be mixed together: Resource files (both local or global) Localized views with a viewengine to call the appropriate view based on culture I'll explain the solutions I tried and all the problems I got with every one of them. Text in resource files, all tags in the view This solution would have me put every text in resources, and every tag in the view, even the inline tags such as [strong] or [span]. Pros: Clean separation, no structure whatsoever in localization. Easy encoding: everything that is returned from the resource gets html encoded. Cons: If I have a paragraph with some strongs, a couple of link etc I have to split it in many resource keys. This is considered to make the view too unreadable and also takes too much time to create it. For the same reason as above, if in two different languages the [strong] text is in different places (like "Il cane di Marco" and "Marcos's dog "), I can't achieve it, since all my tags are in the view. Text and inline tags in resource files, through parameters This method will have the resources contain some placeholders for string.Format, and those placeholders will be filled with inline tags post-encoding. Pros: Clean separation, with just placeholders in the text, so if I am ever to replace [strong] with [em] I do it in the view where I pass it as parameter and it gets changed in every language Cons: Encoding is a bit harder, I have to pre-encode the value from the resource, then use string.Format, and finally return it as Mvc
Tags (comma-separated)
Save Edits
Cancel