S
Shapper
Hello,
I have the following translation dictionary:
public class TranslationDictionary : Dictionary<String, Dictionary<String, String>> { }
A "row" of the translation dictionary might become something as:
new Dictionary<String, Dictionary<String, String>>() { { "Hello", new Dictionary<String, String>() { { "Hello", "en" }, { "Bounjor", "fr" }, { "Olá", "pt" } } }
Note that the first item to be added is also key, e.g, "Hello" in english ("en") is set as the key of that row. However, I would like to fill the Dictionary in a Fluent Way:
translations.For("Hello", "en").Add("Bounjour", "fr").Add("Olá", "pt");
For this I created a TranslationProviderBase class and a TranslationBuilder(Fluent Helper):
public class TranslationBuilder {
private readonly TranslationDictionary _translations;
private readonly String _key;
public TranslationBuilder(String key, TranslationDictionary translations) {
_translations = translations;
_key = key;
}
public TranslationBuilder Add(String text, String culture) {
IDictionary<String, String> filtered;
if (!_translations.TryGetValue(_key, out filtered))
_translations.Add(_key, translations);
return this;
}
}
public class TranslationProviderBase {
public TranslationDictionary Translations { get; private set; }
public TranslationProviderBase() {
Translations = new TranslationDictionary();
}
public TranslationBuilder For(String text, String culture) {
Translations.Add(text, new Dictionary<String, String>() { { text, culture } });
return new TranslationBuilder(text, Translations);
}
}
This is not working ... I am having problems in creating it.
I intend to use TranslationProviderBase class as a base class for RouteTranslationProvider cass, MessageTranslationProvider class and so on ...
Could someone, please, help me out?
Thank You,
Miguel
I have the following translation dictionary:
public class TranslationDictionary : Dictionary<String, Dictionary<String, String>> { }
A "row" of the translation dictionary might become something as:
new Dictionary<String, Dictionary<String, String>>() { { "Hello", new Dictionary<String, String>() { { "Hello", "en" }, { "Bounjor", "fr" }, { "Olá", "pt" } } }
Note that the first item to be added is also key, e.g, "Hello" in english ("en") is set as the key of that row. However, I would like to fill the Dictionary in a Fluent Way:
translations.For("Hello", "en").Add("Bounjour", "fr").Add("Olá", "pt");
For this I created a TranslationProviderBase class and a TranslationBuilder(Fluent Helper):
public class TranslationBuilder {
private readonly TranslationDictionary _translations;
private readonly String _key;
public TranslationBuilder(String key, TranslationDictionary translations) {
_translations = translations;
_key = key;
}
public TranslationBuilder Add(String text, String culture) {
IDictionary<String, String> filtered;
if (!_translations.TryGetValue(_key, out filtered))
_translations.Add(_key, translations);
return this;
}
}
public class TranslationProviderBase {
public TranslationDictionary Translations { get; private set; }
public TranslationProviderBase() {
Translations = new TranslationDictionary();
}
public TranslationBuilder For(String text, String culture) {
Translations.Add(text, new Dictionary<String, String>() { { text, culture } });
return new TranslationBuilder(text, Translations);
}
}
This is not working ... I am having problems in creating it.
I intend to use TranslationProviderBase class as a base class for RouteTranslationProvider cass, MessageTranslationProvider class and so on ...
Could someone, please, help me out?
Thank You,
Miguel