Ejemplo n.º 1
0
        protected void EnsureCollator()
        {
            if (m_pCollator != IntPtr.Zero)
            {
                return;
            }
            // we already have one.
            Icu.UErrorCode uerr = Icu.UErrorCode.U_ZERO_ERROR;

            if (m_stuLocale == String.Empty)
            {
                m_pCollator = Icu.ucol_Open(null, out uerr);
            }

            else
            {
                byte[] rgchLoc = new byte[128];
                Int32  cch     = Icu.uloc_GetName(m_stuLocale, ref rgchLoc, rgchLoc.Length, out uerr);
                Debug.Assert(cch < rgchLoc.Length, "cch < rgchLoc.Length");
                rgchLoc[cch] = 0;
                if (uerr != Icu.UErrorCode.U_ZERO_ERROR)
                {
                    throw new ApplicationException(string.Format("uloc_GetName returned {0}", uerr));
                }

                m_pCollator = Icu.ucol_Open(rgchLoc, out uerr);
            }

            if (!(uerr == Icu.UErrorCode.U_ZERO_ERROR || uerr == Icu.UErrorCode.U_ERROR_WARNING_START || uerr == Icu.UErrorCode.U_USING_DEFAULT_WARNING))
            {
                throw new ApplicationException(string.Format("ucol_Open returned {0}", uerr));
            }
        }
Ejemplo n.º 2
0
            /// --------------------------------------------------------------------------------
            /// <summary>
            /// Displays the name.
            /// </summary>
            /// <param name="sLocale">The s locale.</param>
            /// <returns></returns>
            /// --------------------------------------------------------------------------------
            internal static string DisplayName(string sLocale)
            {
                string sName;

                try
                {
                    CultureInfo ci = new CultureInfo(sLocale.Replace('_', '-'));
                    sName = ci.NativeName;
                }
                catch
                {
                    Icu.UErrorCode uerr = Icu.UErrorCode.U_ZERO_ERROR;
                    Icu.GetDisplayName(sLocale, sLocale, out sName, out uerr);
                }
                return(sName);
            }
Ejemplo n.º 3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="IcuException"/> class.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="errorCode">The error code.</param>
		public IcuException(string message, Icu.UErrorCode errorCode)
			: base(message)
		{
			m_errorCode = errorCode;
		}
Ejemplo n.º 4
0
        private void ExportLDML(LgWritingSystem lgws, LdmlInFolderWritingSystemStore ldmlstore)
        {
            foreach (WritingSystemDefinition wsdT in ldmlstore.WritingSystemDefinitions)
            {
                // Don't bother changing an existing LDML file.
                if (wsdT.RFC4646 == lgws.RFC4646bis)
                {
                    return;
                }
            }
            string sICU = lgws.ICULocale;
            string sLang;
            string sScript;
            string sCountry;
            string sVariant;

            Icu.UErrorCode err = Icu.UErrorCode.U_ZERO_ERROR;
            Icu.GetLanguageCode(sICU, out sLang, out err);
            if (sLang.Length > 3 && sLang.StartsWith("x"))
            {
                sLang = sLang.Insert(1, "-");
            }
            Icu.GetScriptCode(sICU, out sScript, out err);
            Icu.GetCountryCode(sICU, out sCountry, out err);
            Icu.GetVariantCode(sICU, out sVariant, out err);
            if (sVariant == "IPA")
            {
                sVariant = "fonipa";
            }
            Debug.Assert(err == Icu.UErrorCode.U_ZERO_ERROR);
            string sKeyboard;

            if (String.IsNullOrEmpty(lgws.KeymanKeyboard))
            {
                sKeyboard = GetKeyboardName(lgws.Locale);
            }
            else
            {
                sKeyboard = lgws.KeymanKeyboard;
            }
            string sSortUsing = null;
            string sSortRules = null;

            if (lgws.CollationsOS.Count > 0)
            {
                try
                {
                    ILgCollation coll     = lgws.CollationsOS[0];
                    string       sResName = coll.IcuResourceName;
                    string       sRules   = coll.ICURules;
                    int          lcid     = coll.WinLCID;
                    if (!String.IsNullOrEmpty(sRules))
                    {
                        sSortUsing = "CustomICU";
                        sSortRules = sRules;
                    }
                    else if (!String.IsNullOrEmpty(sResName))
                    {
                        sSortUsing = "OtherLanguage";
                        sSortRules = sResName;
                    }
                    else if (lcid != 0)
                    {
                        sSortUsing = "OtherLanguage";
                        System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(lcid);
                        sSortRules = ci.Name;
                    }
                }
                catch
                {
                    // This try-catch shouldn't be needed, but as LT-9545 points out, creating
                    // the collation can crash for some non-repeatable reason.  It's happened
                    // twice on my machine, and once each for a couple of testers.
                }
            }
            WritingSystemDefinition wsd = new WritingSystemDefinition(sLang);

            wsd.Script            = sScript;
            wsd.Region            = sCountry;
            wsd.Variant           = sVariant;
            wsd.LanguageName      = lgws.Name.UserDefaultWritingSystem;
            wsd.Abbreviation      = lgws.Abbr.UserDefaultWritingSystem;
            wsd.RightToLeftScript = lgws.RightToLeft;
            wsd.DefaultFontName   = lgws.DefaultSerif;
            wsd.DefaultFontSize   = 12;                         // pure guesswork - we need a stylesheet or a model change!
            wsd.Keyboard          = sKeyboard;
            if (!String.IsNullOrEmpty(sSortUsing))
            {
                wsd.SortUsing = sSortUsing;
                wsd.SortRules = sSortRules;
            }
            //wsd.NativeName = null;
            //wsd.SpellCheckingId = null;
            //wsd.StoreID = null;
            //wsd.VersionDescription = null;
            //wsd.VersionNumber = null;
            try
            {
                ldmlstore.SaveDefinition(wsd);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(String.Format("Error writing LDML file: lgws.RFC={0}, wsd.RFC={1}; error: {2}",
                                              lgws.RFC4646bis, wsd.RFC4646, ex.Message));
            }
        }