Пример #1
0
 /**
  * Moves all relevant entries in the source dictionary into the destination dictionary
  * @param destination A dictionary of key/value locale pairs that will be modified
  * @param source A dictionary of key/value locale pairs that will be copied into
  * destination
  */
 private void loadTable(OrderedHashtable destination, OrderedHashtable source)
 {
     for (IEnumerator en = source.GetEnumerator(); en.MoveNext();)
     {
         String key = (String)en.Current;
         destination.put(key, (String)source[key]);
     }
 }
Пример #2
0
        public object item(int index)
        {
            if (index < 0 || index >= map.Count)
            {
                return(null);
            }

            OrderedHashtable <MapKey> .Enumerator enumerator = map.GetEnumerator();
            for (int i = 0; i <= index; i++)
            {
                enumerator.MoveNext();
            }
            return(enumerator.Current.Value);
        }
Пример #3
0
        /**
         * Get the set of mappings for a locale.
         *
         * @param locale Locale
         * @returns Hashtable representing text mappings for this locale. Returns null if locale not defined or null.
         */
        public OrderedHashtable getLocaleData(String locale)
        {
            if (locale == null || !this.locales.Contains(locale))
            {
                return(null);
            }

            //It's very important that any default locale contain the appropriate strings to localize the interface
            //for any possible language. As such, we'll keep around a table with only the default locale keys to
            //ensure that there are no localizations which are only present in another locale, which causes ugly
            //and difficult to trace errors.
            OrderedHashtable defaultLocaleKeys = new OrderedHashtable();

            //This table will be loaded with the default values first (when applicable), and then with any
            //language specific translations overwriting the existing values.
            OrderedHashtable data = new OrderedHashtable();

            // If there's a default locale, we load all of its elements into memory first, then allow
            // the current locale to overwrite any differences between the two.
            if (fallbackDefaultLocale && defaultLocale != null)
            {
                ArrayList defaultResources = (ArrayList)localeResources[defaultLocale];
                for (int i = 0; i < defaultResources.Count; ++i)
                {
                    loadTable(data, ((LocaleDataSource)defaultResources[i]).getLocalizedText());
                }
                for (IEnumerator en = data.GetEnumerator(); en.MoveNext();)
                {
                    defaultLocaleKeys.put(en.Current, Boolean.TrueString);
                }
            }

            ArrayList resources = (ArrayList)localeResources[locale];

            for (int i = 0; i < resources.Count; ++i)
            {
                loadTable(data, ((LocaleDataSource)resources[i]).getLocalizedText());
            }

            //If we're using a default locale, now we want to make sure that it has all of the keys
            //that the locale we want to use does. Otherwise, the app will crash when we switch to
            //a locale that doesn't contain the key.
            if (fallbackDefaultLocale && defaultLocale != null)
            {
                String missingKeys = "";
                int    keysmissing = 0;
                for (IEnumerator en = data.GetEnumerator(); en.MoveNext();)
                {
                    String key = (String)en.Current;
                    if (!defaultLocaleKeys.ContainsKey(key))
                    {
                        missingKeys += key + ",";
                        keysmissing++;
                    }
                }
                if (keysmissing > 0)
                {
                    //Is there a good way to localize these exceptions?
                    throw new NoLocalizedTextException("Error loading locale " + locale +
                                                       ". There were " + keysmissing + " keys which were contained in this locale, but were not " +
                                                       "properly registered in the default Locale. Any keys which are added to a locale should always " +
                                                       "be added to the default locale to ensure appropriate functioning.\n" +
                                                       "The missing translations were for the keys: " + missingKeys, missingKeys, defaultLocale);
                }
            }

            return(data);
        }