public Cleanup(Localization l10i) { _l10i = l10i; _cacheDir = "Cache\\" + _l10i.Language + "\\Cleanup\\"; Directory.CreateDirectory(_cacheDir); }
/// <summary>Static constructor of I18NComplete</summary> /// <created author="laurentiu.macovei" date="Fri, 25 Nov 2011 14:55:18 GMT"/> static I18NComplete() { Localizations = new Dictionary<int, Localization>(); if (HttpContext.Current != null) { string _basePathAbsolute = HttpContext.Current.Server.MapPath(I18NComplete.BasePath); if (Directory.Exists(_basePathAbsolute)) { Localization l; foreach (string filename in Directory.GetFiles(_basePathAbsolute, "*.po", SearchOption.AllDirectories)) { var culture = Path.GetFileNameWithoutExtension(filename); culture = Path.GetExtension(culture); culture = culture.StartsWith(".") ? culture.Substring(1) : culture; var cultureHash = string.IsNullOrWhiteSpace(culture) ? I18NComplete.DefaultWorkingLanguageLCID : LCID(culture); if (!Localizations.TryGetValue(cultureHash, out l)) { l = new Localization(); l.LoadFromFile(filename); Localizations.Add(cultureHash, l); } else l.LoadFromFile(filename); } } } if (!Localizations.ContainsKey(I18NComplete.DefaultWorkingLanguageLCID)) Localizations.Add(I18NComplete.DefaultWorkingLanguageLCID, new Localization()); }
public void ApplyStrings(string name, Dictionary<string, string> messages, Localization localization) { Dictionary<string, string> dict; dict = localization.langFile.getSectionKeys (name + ".Strings"); foreach (KeyValuePair<string, string> entry in dict) { messages [entry.Key] = entry.Value; } }
public void Apply(Form form, Localization localization) { FieldInfo messages_field; Dictionary<string, string> dict; dict = localization.langFile.getSectionKeys(form.Name + ".Text"); foreach(KeyValuePair<string, string> entry in dict) { Control[] controls = form.Controls.Find(entry.Key, true); foreach(Control control in controls) { if(!(control is ComboBox)) control.Text = entry.Value; } } messages_field = form.GetType().GetField("strings"); Dictionary<string, string> messages = new Dictionary<string, string>(); if(messages_field != null && messages_field.FieldType == messages.GetType()) { messages = messages_field.GetValue(form) as Dictionary<string, string>; ApplyStrings(form.Name, messages, localization); } messages_field = form.GetType().GetField("tooltip_messages"); Dictionary<string, string[]> tips = new Dictionary<string, string[]>(); if(messages_field != null && messages_field.FieldType == tips.GetType()) { tips = messages_field.GetValue(form) as Dictionary<string, string[]>; messages_field = form.GetType().GetField("toolTip"); ToolTip toolTip = messages_field.GetValue(form) as ToolTip; dict = localization.langFile.getSectionKeys(form.Name + ".ToolTips"); foreach (KeyValuePair<string, string> entry in dict) { if (tips.ContainsKey(entry.Key)) { foreach(string controlName in tips[entry.Key]) { Control[] controls = form.Controls.Find(controlName, true); foreach(Control control in controls) toolTip.SetToolTip(control, entry.Value); } } else { Control[] controls = form.Controls.Find(entry.Key, true); foreach(Control control in controls) { if(control is TabPage) (control as TabPage).ToolTipText = entry.Value; } } } } }
public void Add(string fileName) { if (fileName != null && fileName != "") { Localization localization = new Localization (fileName); if (localization.Language != "") localizations.Add (localization.Language, localization); } }
public void Add(Localization localization) { localizations.Add (localization.Language, localization); }
public void ApplyDialogs (Form form, string[] dialogs, Localization localization) { FieldInfo field; Dictionary<string, string> dict = localization.langFile.getSectionKeys(form.Name + ".Text"); // Applies localization to named dialogs, however they must be public members foreach(string dialogname in dialogs) { field = form.GetType().GetField(dialogname); if(field != null && dict.ContainsKey(dialogname)) { object d = field.GetValue(form); if(d is FileDialog) (d as FileDialog).Title = dict[dialogname]; else if(d is FolderBrowserDialog) (d as FolderBrowserDialog).Description = dict[dialogname]; } } }
public void Apply (Form form, Localization localization) { FieldInfo messages_field; List<ToolStrip> toolstrips = new List<ToolStrip>(); foreach(Control c in form.Controls) { if(c is ToolStrip) toolstrips.Add((ToolStrip)c); } Dictionary<string, string> dict = localization.langFile.getSectionKeys(form.Name + ".Text"); if(dict.ContainsKey(form.Name)) form.Text = dict[form.Name]; foreach(KeyValuePair<string, string> entry in dict) { Control[] controls = form.Controls.Find(entry.Key, true); foreach(Control control in controls) { if(control is ComboBox) { ComboBox cmb = (ComboBox)control; int preserveIndex = cmb.SelectedIndex; cmb.Items.Clear(); cmb.Items.AddRange(entry.Value.Split(';')); cmb.SelectedIndex = preserveIndex; } else control.Text = entry.Value; } foreach(ToolStrip ts in toolstrips) { ToolStripItem[] items = ts.Items.Find(entry.Key, true); foreach(ToolStripItem tsitem in items) { tsitem.Text = entry.Value; } } } messages_field = form.GetType().GetField("strings"); Dictionary<string, string> messages = new Dictionary<string, string>(); if(messages_field != null && messages_field.FieldType == messages.GetType()) { messages = messages_field.GetValue(form) as Dictionary<string, string>; ApplyStrings(form.Name, messages, localization); } messages_field = form.GetType().GetField("tooltip_messages"); Dictionary<string, string[]> tips = new Dictionary<string, string[]>(); if(messages_field != null && messages_field.FieldType == tips.GetType()) { tips = messages_field.GetValue(form) as Dictionary<string, string[]>; messages_field = form.GetType().GetField("toolTip"); ToolTip toolTip = messages_field.GetValue(form) as ToolTip; dict = localization.langFile.getSectionKeys(form.Name + ".ToolTips"); foreach (KeyValuePair<string, string> entry in dict) { if (tips.ContainsKey(entry.Key)) { foreach(string controlName in tips[entry.Key]) { Control[] controls = form.Controls.Find(controlName, true); foreach(Control control in controls) toolTip.SetToolTip(control, entry.Value); } } else { Control[] controls = form.Controls.Find(entry.Key, true); foreach(Control control in controls) { if(control is TabPage) (control as TabPage).ToolTipText = entry.Value; } } } } }
private void AddLocalizations(String language, Localization localization) { if (localizations.ContainsKey(language)) { localizations[language].langFiles.AddRange(localization.langFiles); } else localizations.Add(language, localization); }
public void Add(Localization localization) { AddLocalizations(localization.Language, localization); }
public ViewPrompt(Localization.Views.ViewPrompt prompt) { _prompt = prompt; }
public TypePrompt(Localization.Types.TypePrompt prompt) { _prompt = prompt; }
/// <summary> /// overwrite the Initialize event of the controller /// </summary> /// <param name="requestContext"></param> protected override void Initialize(System.Web.Routing.RequestContext requestContext) { ILocalization localization = new Localization(); // available languages var languages = new List<string>(); languages.Add("en"); languages.Add("de"); // try to find a valid language in Request.UserLanguages CultureInfo ci = CultureInfo.InvariantCulture; string[] userLanguages = requestContext.HttpContext.Request.UserLanguages; if(userLanguages.Length > 0 && languages.Contains(userLanguages[0].Substring(0,2))) { try { ci = new CultureInfo(userLanguages[0]); } catch(CultureNotFoundException) { // do nothing because culture is already set to InvariantCulture and if no matching language is found there is nothing // else to do but fall back on the InvariantCulture. } } #if DEBUG // set the language for debugging to english in order to catch missing translations ci = new CultureInfo("en-US"); #endif localization.UserCultureInfo = ci; base.Initialize(requestContext); }
/// <summary>Gets a translated message version of the supplied text message.</summary> /// <param name="msgID">Text to be translated</param> /// <param name="languageCode">Language to translate into</param> /// <param name="lcid">Specify the Culture LCID for faster access if you know it</param> /// <created author="laurentiu.macovei" date="Fri, 25 Nov 2011 14:55:19 GMT"/> public static Message GetMessage(string msgID, string languageCode = null, int? lcid = null) { if (I18NComplete.HideAllLocalizedText) return Message.Empty; int languageHash = lcid.HasValue ? lcid.Value : string.IsNullOrWhiteSpace(languageCode) ? CultureInfo.CurrentUICulture.LCID : LCID(languageCode); Localization localization; if (!Localizations.TryGetValue(languageHash, out localization)) { if (CultureInfo.CurrentUICulture.IsNeutralCulture) { Localizations[languageHash] = localization = new Localization(); languageHash = I18NComplete.DefaultWorkingLanguageLCID; } else { var nativeCultureHash = CultureInfo.GetCultureInfo(languageHash).Parent.LCID; if (!Localizations.TryGetValue(nativeCultureHash, out localization)) { languageHash = I18NComplete.DefaultWorkingLanguageLCID; Localizations.TryGetValue(languageHash, out localization); } else { //save the specific culture as the generic culture, so it will be found next time Localizations[languageHash] = localization; } } } return localization.GetMessageObject(msgID); }