Exemplo n.º 1
0
		/* === MANAGING LOCALE DATA (TEXT MAPPINGS) === */
		
		/// <summary> Registers a resource file as a source of locale data for the specified
		/// locale.
		/// 
		/// </summary>
		/// <param name="locale">The locale of the definitions provided.
		/// </param>
		/// <param name="resource">A LocaleDataSource containing string data for the locale provided
		/// </param>
		/// <throws>  NullPointerException if resource or locale are null </throws>
		public virtual void  registerLocaleResource(System.String locale, LocaleDataSource resource)
		{
			if (locale == null)
			{
				throw new System.NullReferenceException("Attempt to register a data source to a null locale in the localizer");
			}
			if (resource == null)
			{
				throw new System.NullReferenceException("Attempt to register a null data source in the localizer");
			}
			
			List< LocaleDataSource > resources = new List< LocaleDataSource >();
			if (localeResources.containsKey(locale))
			{
				resources = localeResources.get_Renamed(locale);
			}
			resources.addElement(resource);
			localeResources.put(locale, resources);
			
			if (locale.Equals(currentLocale) || locale.Equals(defaultLocale))
			{
				loadCurrentLocaleResources();
			}
		}
Exemplo n.º 2
0
		private void  InitBlock()
		{
			
			for(String key: source.keySet())
			{
				destination.put(key, stringTree.addString(source.get_Renamed(key)));
			}
			if (locale == null || !this.locales.contains(locale))
			{
				return null;
			}
			stringTree.clear();
			
			//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.
			
			OrderedMap < String, Boolean > defaultLocaleKeys = new OrderedMap < String, Boolean >();
			
			//This table will be loaded with the default values first (when applicable), and then with any
			//language specific translations overwriting the existing values.
			
			OrderedMap < String, PrefixTreeNode > data = new OrderedMap < String, PrefixTreeNode >();
			
			// 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)
			{
				
				for (int i = 0; i < defaultResources.size(); ++i)
				{
					loadTable(data, ((LocaleDataSource) defaultResources.elementAt(i)).getLocalizedText());
				}
				
				for(String key: data.keySet())
				{
					defaultLocaleKeys.put(key, true);
				}
			}
			
			
			for (int i = 0; i < resources.size(); ++i)
			{
				loadTable(data, ((LocaleDataSource) resources.elementAt(i)).getLocalizedText());
			}
			
			//Strings are now immutable
			stringTree.seal();
			
			//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)
			{
				System.String missingKeys = "";
				int keysmissing = 0;
				
				for(String key: data.keySet())
				{
					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;
			
			OrderedMap < String, PrefixTreeNode > mapping = getLocaleData(locale);
			if (mapping == null)
				throw new UnregisteredLocaleException("Attempted to access an undefined locale.");
			return mapping;
			currentLocale = (System.String) ExtUtil.read(dis, new ExtWrapNullable(typeof(System.String)), pf);
			Locale = currentLocale;
		}