Exemplo n.º 1
0
        /// <summary>
        /// Selects the best matching locale id.
        /// </summary>
        public static int SelectLocaleId(IList <int> availableLocaleIds, IList <string> preferredLocales)
        {
            // choose system default if no available locale ids.
            if (availableLocaleIds == null || availableLocaleIds.Count == 0)
            {
                return(ComUtils.LOCALE_SYSTEM_DEFAULT);
            }

            // choose system default if no preferred locales.
            if (preferredLocales == null || preferredLocales.Count == 0)
            {
                return(availableLocaleIds[0]);
            }

            // look for an exact match.
            for (int ii = 0; ii < preferredLocales.Count; ii++)
            {
                for (int jj = 0; jj < availableLocaleIds.Count; jj++)
                {
                    if (ComUtils.CompareLocales(availableLocaleIds[jj], preferredLocales[ii], false))
                    {
                        return(availableLocaleIds[jj]);
                    }
                }
            }

            // look for a match on the language only.
            for (int ii = 0; ii < preferredLocales.Count; ii++)
            {
                for (int jj = 0; jj < availableLocaleIds.Count; jj++)
                {
                    if (ComUtils.CompareLocales(availableLocaleIds[jj], preferredLocales[ii], true))
                    {
                        return(availableLocaleIds[jj]);
                    }
                }
            }

            // return the first avialable locale.
            return(availableLocaleIds[0]);
        }