Ejemplo n.º 1
0
        public String GetString(String key, Object[] parameters)
        {
            if (defaultBundle == null)
            {
                try
                {
                    defaultBundle = ResourceBundle.GetBundle(defaultBundleBaseName, locale);
                }catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            if (replaceBundle == null && replaceBundleName != null)
            {
                replaceBundle = ResourceBundle.GetBundle(replaceBundleName, locale);
            }
            String value = null;

            if (replaceBundle != null)
            {
                try
                {
                    value = replaceBundle.GetString(key, parameters);
                }
                catch (MissingResourceException e)
                {
                    Console.WriteLine(e);
                    if (defaultBundle != null)
                    {
                        value = defaultBundle.GetString(key, parameters);
                    }
                }
            }
            return(value);
        }
Ejemplo n.º 2
0
        private String ComputeLocalizedLevelName(Locale newLocale)
        {
            ResourceBundle rb = ResourceBundle.GetBundle(ResourceBundleName_Renamed, newLocale);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String localizedName = rb.getString(name);
            String localizedName = rb.GetString(Name_Renamed);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final boolean isDefaultBundle = defaultBundle.equals(resourceBundleName);
            bool isDefaultBundle = DefaultBundle.Equals(ResourceBundleName_Renamed);

            if (!isDefaultBundle)
            {
                return(localizedName);
            }

            // This is a trick to determine whether the name has been translated
            // or not. If it has not been translated, we need to use Locale.ROOT
            // when calling toUpperCase().
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Locale rbLocale = rb.getLocale();
            Locale rbLocale = rb.Locale;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.Locale locale = java.util.Locale.ROOT.equals(rbLocale) || name.equals(localizedName.toUpperCase(java.util.Locale.ROOT)) ? java.util.Locale.ROOT : rbLocale;
            Locale locale = Locale.ROOT.Equals(rbLocale) || Name_Renamed.Equals(localizedName.ToUpperCase(Locale.ROOT)) ? Locale.ROOT : rbLocale;

            // ALL CAPS in a resource bundle's message indicates no translation
            // needed per Oracle translation guideline.  To workaround this
            // in Oracle JDK implementation, convert the localized level name
            // to uppercase for compatibility reason.
            return(Locale.ROOT.Equals(locale) ? Name_Renamed : localizedName.ToUpperCase(locale));
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
        private void ReadObject(ObjectInputStream @in)
        {
            // We have to call defaultReadObject first.
            @in.DefaultReadObject();

            // Read version number.
            sbyte major = @in.ReadByte();
            sbyte minor = @in.ReadByte();

            if (major != 1)
            {
                throw new IOException("LogRecord: bad version: " + major + "." + minor);
            }
            int len = @in.ReadInt();

            if (len == -1)
            {
                Parameters_Renamed = null;
            }
            else
            {
                Parameters_Renamed = new Object[len];
                for (int i = 0; i < Parameters_Renamed.Length; i++)
                {
                    Parameters_Renamed[i] = @in.ReadObject();
                }
            }
            // If necessary, try to regenerate the resource bundle.
            if (ResourceBundleName_Renamed != null)
            {
                try
                {
                    // use system class loader to ensure the ResourceBundle
                    // instance is a different instance than null loader uses
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ResourceBundle bundle = ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), ClassLoader.getSystemClassLoader());
                    ResourceBundle bundle = ResourceBundle.GetBundle(ResourceBundleName_Renamed, Locale.Default, ClassLoader.SystemClassLoader);
                    ResourceBundle_Renamed = bundle;
                }
                catch (MissingResourceException)
                {
                    // This is not a good place to throw an exception,
                    // so we simply leave the resourceBundle null.
                    ResourceBundle_Renamed = null;
                }
            }

            NeedToInferCaller = false;
        }
Ejemplo n.º 4
0
        public static void UpdateFromBundle(String bundleName, DataInfo info)
        {
            ResourceBundle r      = ResourceBundle.GetBundle(bundleName, Locale.Current);
            String         prefix = info.GetDataClassName();

            DataField[] fs = info.GetFields();
            for (int i = 0; i < fs.Length; i++)
            {
                try
                {
                    fs[i].SetFieldTitle(r.GetString(prefix + "." + fs[i].GetFieldName()));
                }
                catch (MissingResourceException)
                {
                    Console.WriteLine("Missing Resource " + prefix + "." + fs[i].GetFieldName());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Resource not found for : " + prefix + "." + fs[i].GetFieldName() + "\n" + e);
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Load the i-th bundle and implement wildcard resolution.
 /// </summary>
 ///
 private void Load(int i)
 {
     if (bundles[i] == null)
     {
         bool tryWildcard = false;
         try {
             bundles[i] = ResourceBundle.GetBundle(baseNames[i], locale);
             if (bundles[i].GetLocale().Equals(locale))
             {
                 return;
             }
             if (locale.GetCountry().Length != 0 &&
                 i != bundles.Length - 1)
             {
                 tryWildcard = true;
             }
         } catch (MissingManifestResourceException e) {
             if (i == bundles.Length - 1)
             {
                 throw e;
             }
             tryWildcard = true;
         }
         if (tryWildcard)
         {
             Locale wildcard = new Locale("xx", locale.GetCountry(),
                                          locale.GetLanguage());
             try {
                 bundles[i] = ResourceBundle.GetBundle(baseNames[i],
                                                       wildcard);
             } catch (MissingManifestResourceException e_0) {
                 if (bundles[i] == null)
                 {
                     throw e_0;
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
        // recursively build bundle
        private static ResourceBundle Instantiate(String name)
        {
            ResourceBundle b = LoadFromCache(name);

            if (b == null)
            {
                ResourceBundle parent = null;
                int            i      = name.LastIndexOf('_');

                // TODO: convert this to use ULocale
                Locale rootLocale = new Locale("", "", "");

                if (i != -1)
                {
                    parent = Instantiate(name.Substring(0, (i) - (0)));
                }
                try {
                    Locale locale = rootLocale;
                    i = name.IndexOf('_');
                    if (i != -1)
                    {
                        locale = IBM.ICU.Impl.LocaleUtility.GetLocaleFromName(name.Substring(i + 1));
                    }
                    else
                    {
                        i = name.Length;
                    }

                    Assembly cl = typeof(ICULocaleData).Assembly;
                    if (cl == null)
                    {
                        // we're on the bootstrap
                        cl = System.Reflection.Assembly.GetEntryAssembly();
                    }
                    Type cls = cl.GetType(name);
                    if (typeof(ICUListResourceBundle).IsAssignableFrom(cls))
                    {
                        ICUListResourceBundle bx = (ICUListResourceBundle)Activator.CreateInstance(cls);

                        if (parent != null)
                        {
                            bx.SetParentX(parent);
                        }
                        bx.icuLocale = locale;
                        b            = bx;
                        // System.out.println("iculistresourcebundle: " + name +
                        // " is " + b);
                    }
                    else
                    {
                        b = ResourceBundle.GetBundle(name.Substring(0, (i) - (0)), locale);
                        // System.out.println("resourcebundle: " + name + " is " +
                        // b);
                    }
                    AddToCache(name, b);
                } catch (TypeLoadException e) {
                    int j = name.IndexOf('_');
                    int k = name.LastIndexOf('_');
                    // if a bogus locale is passed then the parent should be
                    // the default locale not the root locale!
                    if (k == j && j != -1)
                    {
                        String locName     = name.Substring(j + 1, (name.Length) - (j + 1));
                        String defaultName = IBM.ICU.Util.ULocale.GetDefault().ToString();

                        if (!locName.Equals(rootLocale.ToString()) &&
                            defaultName.IndexOf(locName) == -1)
                        {
                            String bundle = name.Substring(0, (j) - (0));
                            parent = Instantiate(bundle + "_" + defaultName);
                        }
                    }
                    b = parent;
                } catch (Exception e_0) {
                    System.Console.Out.WriteLine("failure");
                    System.Console.Out.WriteLine(e_0);
                }
            }
            // if(b==null){
            // throw new
            // MissingResourceException("Could not load data "+name,"","");
            // }
            return(b);
        }
Ejemplo n.º 7
0
 /// <summary>Get a resource bundle</summary>
 /// <param name="bundleName">of the resource</param>
 /// <returns>the resource bundle</returns>
 /// <exception cref="Sharpen.MissingResourceException"/>
 public static ResourceBundle GetBundle(string bundleName)
 {
     return(ResourceBundle.GetBundle(bundleName.Replace('$', '_'), CultureInfo.CurrentCulture
                                     , Sharpen.Thread.CurrentThread().GetContextClassLoader()));
 }