Beispiel #1
0
		/* === INFORMATION ABOUT AVAILABLE LOCALES === */
		
		/// <summary> Create a new locale (with no mappings). Do nothing if the locale is already defined.
		/// 
		/// </summary>
		/// <param name="locale">Locale to add. Must not be null.
		/// </param>
		/// <returns> True if the locale was not already defined.
		/// </returns>
		/// <throws>  NullPointerException if locale is null </throws>
		public virtual bool addAvailableLocale(System.String locale)
		{
			if (locale == null)
			{
				throw new System.NullReferenceException("unexpected null locale");
			}
			if (hasLocale(locale))
			{
				return false;
			}
			else
			{
				locales.addElement(locale);
				
				localeResources.put(locale, new List< LocaleDataSource >());
				return true;
			}
		}
        private void  parseAndAdd(OrderedMap locale, System.String line, int curline)
        {
            //trim whitespace.
            line = line.Trim();

            //clear comments
            while (line.IndexOf("#") != -1)
            {
                line = line.Substring(0, (line.IndexOf("#")) - (0));
            }
            if (line.IndexOf('=') == -1)
            {
                // TODO: Invalid line. Empty lines are fine, especially with comments,
                // but it might be hard to get all of those.
                if (line.Trim().Equals(""))
                {
                    //Empty Line
                }
                else
                {
                    System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: " + line);
                }
            }
            else
            {
                //Check to see if there's anything after the '=' first. Otherwise there
                //might be some big problems.
                if (line.IndexOf('=') != line.Length - 1)
                {
                    System.String value_Renamed = line.Substring(line.IndexOf('=') + 1, (line.Length) - (line.IndexOf('=') + 1));
                    locale.put(line.Substring(0, (line.IndexOf('=')) - (0)), value_Renamed);
                }
                else
                {
                    System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: '" + line + "'. No value follows the '='.");
                }
            }
        }
Beispiel #3
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;
		}
Beispiel #4
0
        private void  InitBlock()
        {
            // TODO: This might very well fail. Best way to handle?

            OrderedMap <String, String> locale = new OrderedMap <String, String>();
            int chunk = 100;

            System.IO.StreamReader isr;
            isr = new InputStreamReader(is_Renamed, "UTF-8");
            bool done = false;

            char[] cbuf    = new char[chunk];
            int    offset  = 0;
            int    curline = 0;

            System.String line = "";
            while (!done)
            {
                //UPGRADE_TODO: Method 'java.io.InputStreamReader.read' was converted to 'System.IO.StreamReader.Read' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioInputStreamReaderread_char[]_int_int'"
                int read = isr.Read(cbuf, offset, chunk - offset);
                if (read == -1)
                {
                    done = true;
                    if ((System.Object)line != (System.Object) "")
                    {
                        parseAndAdd(locale, line, curline);
                    }
                    break;
                }
                System.String stringchunk = new System.String(cbuf, offset, read);

                int index = 0;

                while (index != -1)
                {
                    //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
                    int nindex = stringchunk.IndexOf('\n', index);
                    //UTF-8 often doesn't encode with newline, but with CR, so if we
                    //didn't find one, we'll try that
                    if (nindex == -1)
                    {
                        //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'"
                        nindex = stringchunk.IndexOf('\r', index);
                    }
                    if (nindex == -1)
                    {
                        line += stringchunk.Substring(index);
                        break;
                    }
                    else
                    {
                        line += stringchunk.Substring(index, (nindex) - (index));
                        //Newline. process our string and start the next one.
                        curline++;
                        parseAndAdd(locale, line, curline);
                        line = "";
                    }
                    index = nindex + 1;
                }
            }
            is_Renamed.close();
            return(locale);

            //trim whitespace.
            line = line.Trim();

            //clear comments
            while (line.IndexOf("#") != -1)
            {
                line = line.Substring(0, (line.IndexOf("#")) - (0));
            }
            if (line.IndexOf('=') == -1)
            {
                // TODO: Invalid line. Empty lines are fine, especially with comments,
                // but it might be hard to get all of those.
                if (line.Trim().Equals(""))
                {
                    //Empty Line
                }
                else
                {
                    System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: " + line);
                }
            }
            else
            {
                //Check to see if there's anything after the '=' first. Otherwise there
                //might be some big problems.
                if (line.IndexOf('=') != line.Length - 1)
                {
                    System.String value_Renamed = line.Substring(line.IndexOf('=') + 1, (line.Length) - (line.IndexOf('=') + 1));
                    locale.put(line.Substring(0, (line.IndexOf('=')) - (0)), value_Renamed);
                }
                else
                {
                    System.Console.Out.WriteLine("Invalid line (#" + curline + ") read: '" + line + "'. No value follows the '='.");
                }
            }
        }