c# - How to translate the OlCategoryColor? -
i'm using microsoft.office.interop.outlook;
allows me use olcategorycolor
. in particular i've this:
dictionary<olcategorycolor, keyvaluepair<string, string>> categorycolor; categorycolor = new dictionary<olcategorycolor, keyvaluepair<string, string>> { {olcategorycolor.olcategorycolorred, new keyvaluepair<string, string>("#e7a1a2", "7")} };
to name of color, this:
foreach (var outlookcolor in categorycolor) { outlookcolor.key.tostring().remove(0, "olcategorycolor".length); }
it returns red
, possible take italian language or other languages?
here simple solution, may want tweak little depending on wherever want support many languages or italian:
public enum language { english, italian } public static class localizationhelper { private static idictionary<string, string> eng2italiancolor = new dictionary<string, string> { { "red", "rosso" }, { "black", "nero" }, { "blue", "azzurro" }, // other ... }; public static string getcolorname(olcategorycolor color, language language) { var englishcolorname = color.tostring().remove(0, "olcategorycolor".length); if (language == language.english) { return englishcolorname; } else if (language == language.italian) { if (eng2italiancolor.containskey(englishcolorname)) return eng2italiancolor[englishcolorname]; else throw new argumentexception( "missing translation english italian color: " + englishcolorname); } else { throw new argumentexception("unsupported language: " + language); } } } // use: var colorname = localizationhelper.getcolorname(outlookcolor.key, language.italian);
if google little maybe find ready translation table colors, used simple dict
linux utility allows translate words command line.
depending on application writing, there may case need translate other strings/messages, in case should check tutorials on globalization solutions .net - create several resource files - 1 per language , use resourcemanager or other class load strings based on thread.currentculture
. in case resource name may use e.g. color_red
, each language provide appropriate translation. quick tutorial here: http://www.aspsnippets.com/articles/what-is-globalization-and-localization-and-their-differences-in-aspnet.aspx
Comments
Post a Comment