I have a bit of a predicament involving translation of dynamic content, I have a model which is bound to collections of Questions and Answers, which gets looped through on my MVC view and displayed along with HTML to contain them, as per the below code.
@if (questions.Length == answers.Length)
{
for (int i = 0; i < questions.Length; i++)
{
var html = string.Format(@"
<div class='panel-group' id='accordion{1}'>
<div class='panel panel-default'>
<div class='panel-heading' data-toggle='collapse' data-parent='#accordion{1}' data-target='#collapse{1}'>
<h4 class='panel-title'>
<a class='accordion-toggle collapsed'>{0}</a>
</h4>
</div>
<div id='collapse{1}' class='panel-collapse collapse '>
<div class='panel-body'>
{2}
</div>
</div>
</div>", questions[i], IDGenerator, answers[i]);
@Html.Raw(html)
IDGenerator.Append("1");
}
}
@{
IDGenerator.Clear();
}
I have managed to localize static strings fine, by replacing those strings with values in my RESX pertaining to the current culture.
However, I need my FAQ Questions and answers to be localizable as well, is there a way to do this at all? I'd like to retain the use of RESX if possible.
you can use this tutorial to localize your entities as long as you have more than 2 languages ... other approach if you only have 2 languages for your system is to save the localized value in the same table of the entity under 'TextFrench' for example (but i don't recommend this approach as it's limited)
also you can use a caching mechanism for performance.