Orchard Database Translations Module
Technically it isn’t my first module, but the first to enter the Gallery. And it’s called the Database Translations Module.
Two multilingual projects at Q42 ran into the problem that the editors weren’t able to translate the strings we were implementing in the code. But we were using the nifty T function in Orchard that translates strings.
So the goal was to make the strings editable. But we also made it possible to flush the dictionary cache once you edited strings, so the changes would be visible instantly without affecting performance.
The heart of the application is our own ILocalizedStringManager, which takes over from the DefaultLocalizedStringManager.
[OrchardSuppressDependency("Orchard.Localization.Services.DefaultLocalizedStringManager")]
public class LiveLocalizedStringManager : ILocalizedStringManager
{
It’s an exact copy of the DefaultLocalizedStringManager, but with one minor change: the LoadTranslationsForCulture function gets its content from the database instead of from *.po files.
private IDictionary<string, string> LoadTranslationsForCulture(string culture, AcquireContext<string> context)
{
IDictionary<string, string> result = new Dictionary<string, string>();
var translations = _localizationService.GetTranslations(culture);
foreach (var t in translations)
{
var scope = t.Context;
var id = t.Key;
string scopedKey = (scope + "|" + id).ToLowerInvariant();
if (!result.ContainsKey(scopedKey))
{
result.Add(scopedKey, t.Translation);
}
else
{
result[scopedKey] = t.Translation;
}
}
return result;
}
There’s still a lot of features I want to implement, but I’ve already heard some positive feedback from the Orchard community. If you want to have a further look, check out the module on github.