Beispiel #1
0
        public void SetLanguage(string langCode, string langName)
        {
            if (langCode == null)
            {
                langCode = String.Empty;
            }
            if (langName == null)
            {
                langName = String.Empty;
            }

            CultureInfo cultureInfo = null;

            try
            {
                cultureInfo = CultureInfo.CreateSpecificCulture(String.Format("{0}-{1}", langCode, langCode));
                if (cultureInfo.IsNeutralCulture)
                {
                    cultureInfo = null;
                }
            }
            catch
            {
                var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
                cultureInfo = (from c in cultures
                               let subLanguage = c.Name.Substring(c.Name.Length - 2, 2)
                                                 where c.NativeName == langName ||
                                                 String.Compare(subLanguage, langCode, true) == 0 ||
                                                 String.Compare(c.Name, langCode, true) == 0
                                                 select c).FirstOrDefault();
            }

            if (_cultureInfo == null || cultureInfo == null || _cultureInfo.Name != cultureInfo.Name)
            {
                _cultureInfo = cultureInfo;
            }
            else
            {
                return;
            }

            int currCodepage = GetDefaultCodepage(Thread.CurrentThread.CurrentCulture);

            if (currCodepage == 0 || cultureInfo == null)
            {
                var languageSelection = new LanguageSelection();
                if (languageSelection.ShowDialog() == DialogResult.OK)
                {
                    langCode    = languageSelection.GetSelectedLangCode();
                    cultureInfo = CultureInfo.CreateSpecificCulture(langCode);
                }
                else
                {
                    return;
                }
            }

            int gdiCharSet = GetFontCharset(cultureInfo.TextInfo.ANSICodePage);

            this.Clear();         // Clear the content
            if (this.Rtf == null) // Sometimes happens, setting to empty, fills in default Rtf
            {
                this.Rtf = String.Empty;
            }

            this.Rtf = this.Rtf.Replace("ansicpg" + currCodepage.ToString(),
                                        "ansicpg" + cultureInfo.TextInfo.ANSICodePage.ToString());
            this.Rtf = this.Rtf.Replace("deflang" + Thread.CurrentThread.CurrentCulture.LCID.ToString(),
                                        "deflang" + cultureInfo.LCID.ToString());
            this.Rtf = this.Rtf.Replace("fcharset" + this.Font.GdiCharSet.ToString(),
                                        "fcharset" + gdiCharSet.ToString());
            this.Font = new Font(this.Font.FontFamily, this.Font.SizeInPoints, this.Font.Style,
                                 GraphicsUnit.Point, (byte)gdiCharSet);
        }
Beispiel #2
0
        public void SetLanguage(string langCode, string langName)
        {
            if (langCode == null) langCode = String.Empty;
            if (langName == null) langName = String.Empty;

            CultureInfo cultureInfo = null;
            try {
                cultureInfo = CultureInfo.CreateSpecificCulture(String.Format("{0}-{1}", langCode, langCode));
                if (cultureInfo.IsNeutralCulture)
                    cultureInfo = null;
            } catch {
                var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
                cultureInfo = (from c in cultures
                               let subLanguage = c.Name.Substring(c.Name.Length - 2, 2)
                               where c.NativeName == langName ||
                                     String.Compare(subLanguage, langCode, true) == 0 ||
                                     String.Compare(c.Name, langCode, true) == 0
                               select c).FirstOrDefault();
            }

            if (_cultureInfo == null || cultureInfo == null || _cultureInfo.Name != cultureInfo.Name)
                _cultureInfo = cultureInfo;
            else return;

            int currCodepage = GetDefaultCodepage(Thread.CurrentThread.CurrentCulture);
            if (currCodepage == 0 || cultureInfo == null) {
                var languageSelection = new LanguageSelection();
                if (languageSelection.ShowDialog() == DialogResult.OK) {
                    langCode = languageSelection.GetSelectedLangCode();
                    cultureInfo = CultureInfo.CreateSpecificCulture(langCode);
                } else return;
            }

            int gdiCharSet = GetFontCharset(cultureInfo.TextInfo.ANSICodePage);

            this.Clear(); // Clear the content
            if (this.Rtf == null) // Sometimes happens, setting to empty, fills in default Rtf
                this.Rtf = String.Empty;

            this.Rtf = this.Rtf.Replace("ansicpg" + currCodepage.ToString(),
                                        "ansicpg" + cultureInfo.TextInfo.ANSICodePage.ToString());
            this.Rtf = this.Rtf.Replace("deflang" + Thread.CurrentThread.CurrentCulture.LCID.ToString(),
                                        "deflang" + cultureInfo.LCID.ToString());
            this.Rtf = this.Rtf.Replace("fcharset" + this.Font.GdiCharSet.ToString(),
                                        "fcharset" + gdiCharSet.ToString());
            this.Font = new Font(this.Font.FontFamily, this.Font.SizeInPoints, this.Font.Style,
                                 GraphicsUnit.Point, (byte)gdiCharSet);
        }