当前位置: 首页>>代码示例>>Java>>正文


Java ResourceBundle.getLocale方法代码示例

本文整理汇总了Java中java.util.ResourceBundle.getLocale方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceBundle.getLocale方法的具体用法?Java ResourceBundle.getLocale怎么用?Java ResourceBundle.getLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.ResourceBundle的用法示例。


在下文中一共展示了ResourceBundle.getLocale方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLogMessageText

import java.util.ResourceBundle; //导入方法依赖的package包/类
protected String getLogMessageText(LogMessageIdentifier identifier,
        String... params) {
    String text;
    try {
        String msgId = identifier.getMsgId();
        ResourceBundle bundle = getResourceBundle();
        text = bundle.getString(msgId);
        if (params != null) {
            MessageFormat mf = new MessageFormat(text, bundle.getLocale());
            params = escapeParams(params);
            text = mf.format(params, new StringBuffer(), null).toString();
        }
        text = addMsgIdToMsg(identifier, text);
    } catch (MissingResourceException e) {
        text = "?? key '" + identifier.name() + "' not found ??";
    }

    return text;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:Log4jLogger.java

示例2: computeLocalizedLevelName

import java.util.ResourceBundle; //导入方法依赖的package包/类
private String computeLocalizedLevelName(Locale newLocale) {
    ResourceBundle rb = ResourceBundle.getBundle(resourceBundleName, newLocale);
    final String localizedName = rb.getString(name);

    final boolean isDefaultBundle = defaultBundle.equals(resourceBundleName);
    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().
    final Locale rbLocale = rb.getLocale();
    final Locale locale =
            Locale.ROOT.equals(rbLocale)
            || name.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 : localizedName.toUpperCase(locale);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:Level.java

示例3: StringManager

import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
 * Creates a new StringManager for a given package. This is a
 * private method and all access to it is arbitrated by the
 * static getManager method call so that only one StringManager
 * per package will be created.
 *
 * @param packageName Name of package to create StringManager for.
 */
private StringManager(String packageName) {
    String bundleName = packageName + ".LocalStrings";
    ResourceBundle tempBundle = null;
    try {
        tempBundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
    } catch( MissingResourceException ex ) {
        // Try from the current loader (that's the case for trusted apps)
        // Should only be required if using a TC5 style classloader structure
        // where common != shared != server
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if( cl != null ) {
            try {
                tempBundle = ResourceBundle.getBundle(
                        bundleName, Locale.getDefault(), cl);
            } catch(MissingResourceException ex2) {
                // Ignore
            }
        }
    }
    // Get the actual locale, which may be different from the requested one
    if (tempBundle != null) {
        locale = tempBundle.getLocale();
    } else {
        locale = null;
    }
    bundle = tempBundle;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:StringManager.java

示例4: computeLocalizedLevelName

import java.util.ResourceBundle; //导入方法依赖的package包/类
private String computeLocalizedLevelName(Locale newLocale) {
    // Resource bundle should be loaded from the defining module
    // or its defining class loader, if it's unnamed module,
    // of this Level instance that can be a custom Level subclass;
    Module module = this.getClass().getModule();
    ResourceBundle rb = RbAccess.RB_ACCESS.getBundle(resourceBundleName,
            newLocale, module);

    final String localizedName = rb.getString(name);
    final boolean isDefaultBundle = defaultBundle.equals(resourceBundleName);
    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().
    final Locale rbLocale = rb.getLocale();
    final Locale locale =
            Locale.ROOT.equals(rbLocale)
            || name.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 : localizedName.toUpperCase(locale);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:Level.java

示例5: StringManager

import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
 * Creates a new StringManager for a given package. This is a private method
 * and all access to it is arbitrated by the static getManager method call
 * so that only one StringManager per package will be created.
 *
 * @param packageName
 *            Name of package to create StringManager for.
 */
private StringManager(String packageName) {
	String bundleName = packageName + ".LocalStrings";
	ResourceBundle tempBundle = null;
	try {
		tempBundle = ResourceBundle.getBundle(bundleName, Locale.getDefault());
	} catch (MissingResourceException ex) {
		// Try from the current loader (that's the case for trusted apps)
		// Should only be required if using a TC5 style classloader
		// structure
		// where common != shared != server
		ClassLoader cl = Thread.currentThread().getContextClassLoader();
		if (cl != null) {
			try {
				tempBundle = ResourceBundle.getBundle(bundleName, Locale.getDefault(), cl);
			} catch (MissingResourceException ex2) {
				// Ignore
			}
		}
	}
	// Get the actual locale, which may be different from the requested one
	if (tempBundle != null) {
		locale = tempBundle.getLocale();
	} else {
		locale = null;
	}
	bundle = tempBundle;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:36,代码来源:StringManager.java

示例6: loadBundle

import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
 * Create a ResourceBundle and put it in an EL-reachable scope.
 *
 * @param resBundleName - String containing name of class containing the 
 *                        resource bundle.
 * @param resBundleKey - String key for the resource bundle
 */
@SuppressWarnings("unchecked")
static void loadBundle(String resBundleName, String resBundleKey)
{
  FacesContext facesContext = FacesContext.getCurrentInstance();
  Map<String, Object> applicationMap =
    facesContext.getExternalContext().getApplicationMap();

  // Get the view root locale
  Locale requestLocale = facesContext.getViewRoot().getLocale();

  // Make sure it is not null
  if (requestLocale == null)
  {
    requestLocale = facesContext.getApplication().getDefaultLocale();
  }

  // Is there a bundle with this key already on the session map?
  _BundleMap bundleMap = (_BundleMap) applicationMap.get(resBundleKey);

  // if so, get its locale.  If the locale has not
  // changed, just return, i.e. use the existing bundle
  if (bundleMap != null)
  {
    Locale bundleLocale = bundleMap.getLocale();

    if (bundleLocale == null)
    {
      ResourceBundle rb = bundleMap.getBundle();
      bundleLocale = rb.getLocale();
    }

    if (requestLocale == bundleLocale)
    {
      // the bundle on the applicationMap is ok so just return
      return;
    }
  }

  String bundleName = null;

  if (resBundleName != null)
  {
    // if _bundleName is an EL, then get its value
    if (ContainerUtils.isValueReference(resBundleName))
    {
      bundleName = MenuUtils.getBoundValue(resBundleName, String.class);
    }
    else
    {
      bundleName = resBundleName ;
    }
  }

  final ResourceBundle bundle;

  try
  {
    bundle = ResourceBundle.getBundle(bundleName, requestLocale);
  }
  catch (MissingResourceException e)
  {
    _LOG.severe("RESOURCE_BUNDLE_NOT_FOUND", bundleName);
    _LOG.severe(e);
    return;
  }

  // Put the bundle in the map.  At this point the key is
  // unique because of the handler Id we inserted when loadBundle
  // was called.
  applicationMap.put(resBundleKey, new _BundleMap(bundle, requestLocale));
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:79,代码来源:MenuUtils.java

示例7: _BundleMap

import java.util.ResourceBundle; //导入方法依赖的package包/类
public _BundleMap(ResourceBundle bundle)
{
  _bundle = bundle;
  _locale = bundle.getLocale();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:6,代码来源:MenuUtils.java

示例8: loadBundle

import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
 * Create a ResourceBundle and put it in an EL-reachable scope.
 *
 * @param resBundleName - String containing name of class containing the 
 *                        resource bundle.
 * @param resBundleKey - String key for the resource bundle
 */
@SuppressWarnings("unchecked")
static public void loadBundle(String resBundleName, String resBundleKey)
{
  FacesContext facesContext = FacesContext.getCurrentInstance();
  Map<String, Object> applicationMap =
    facesContext.getExternalContext().getApplicationMap();

  // Get the view root locale
  Locale requestLocale = facesContext.getViewRoot().getLocale();

  // Make sure it is not null
  if (requestLocale == null)
  {
    requestLocale = facesContext.getApplication().getDefaultLocale();
  }

  // Is there a bundle with this key already on the session map?
  _BundleMap bundleMap = (_BundleMap) applicationMap.get(resBundleKey);

  // if so, get its locale.  If the locale has not
  // changed, just return, i.e. use the existing bundle
  if (bundleMap != null)
  {
    Locale bundleLocale = bundleMap.getLocale();

    if (bundleLocale == null)
    {
      ResourceBundle rb = bundleMap.getBundle();
      bundleLocale = rb.getLocale();
    }

    if (requestLocale == bundleLocale)
    {
      // the bundle on the applicationMap is ok so just return
      return;
    }
  }

  String bundleName = null;

  if (resBundleName != null)
  {
    // if _bundleName is an EL, then get its value
    if (ContainerUtils.isValueReference(resBundleName))
    {
      bundleName = MenuUtils.getBoundValue(resBundleName, String.class);
    }
    else
    {
      bundleName = resBundleName ;
    }
  }

  final ResourceBundle bundle;

  try
  {
    bundle = ResourceBundle.getBundle(bundleName, requestLocale);
  }
  catch (MissingResourceException e)
  {
    _LOG.severe("RESOURCE_BUNDLE_NOT_FOUND", bundleName);
    _LOG.severe(e);
    return;
  }

  // Put the bundle in the map.  At this point the key is
  // unique because of the handler Id we inserted when loadBundle
  // was called.
  applicationMap.put(resBundleKey, new _BundleMap(bundle, requestLocale));
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:79,代码来源:MenuUtils.java

示例9: StringManager

import java.util.ResourceBundle; //导入方法依赖的package包/类
private StringManager(ResourceBundle bundle )
   {
this.bundle=bundle;
       locale = bundle.getLocale();
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:6,代码来源:StringManager.java

示例10: initializeData

import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
 * Initializes this DateFormatSymbols with the locale data. This method uses
 * a cached DateFormatSymbols instance for the given locale if available. If
 * there's no cached one, this method creates an uninitialized instance and
 * populates its fields from the resource bundle for the locale, and caches
 * the instance. Note: zoneStrings isn't initialized in this method.
 */
private void initializeData(Locale locale) {
    SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
    DateFormatSymbols dfs;
    if (ref == null || (dfs = ref.get()) == null) {
        if (ref != null) {
            // Remove the empty SoftReference
            cachedInstances.remove(locale, ref);
        }
        dfs = new DateFormatSymbols(false);

        // Initialize the fields from the ResourceBundle for locale.
        LocaleProviderAdapter adapter
            = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
        // Avoid any potential recursions
        if (!(adapter instanceof ResourceBundleBasedAdapter)) {
            adapter = LocaleProviderAdapter.getResourceBundleBased();
        }
        ResourceBundle resource
            = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);

        dfs.locale = locale;
        // JRE and CLDR use different keys
        // JRE: Eras, short.Eras and narrow.Eras
        // CLDR: long.Eras, Eras and narrow.Eras
        if (resource.containsKey("Eras")) {
            dfs.eras = resource.getStringArray("Eras");
        } else if (resource.containsKey("long.Eras")) {
            dfs.eras = resource.getStringArray("long.Eras");
        } else if (resource.containsKey("short.Eras")) {
            dfs.eras = resource.getStringArray("short.Eras");
        }
        dfs.months = resource.getStringArray("MonthNames");
        dfs.shortMonths = resource.getStringArray("MonthAbbreviations");
        dfs.ampms = resource.getStringArray("AmPmMarkers");
        dfs.localPatternChars = resource.getString("DateTimePatternChars");

        // Day of week names are stored in a 1-based array.
        dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
        dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));

        // Put dfs in the cache
        ref = new SoftReference<>(dfs);
        SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
        if (x != null) {
            DateFormatSymbols y = x.get();
            if (y == null) {
                // Replace the empty SoftReference with ref.
                cachedInstances.replace(locale, x, ref);
            } else {
                ref = x;
                dfs = y;
            }
        }
        // If the bundle's locale isn't the target locale, put another cache
        // entry for the bundle's locale.
        Locale bundleLocale = resource.getLocale();
        if (!bundleLocale.equals(locale)) {
            SoftReference<DateFormatSymbols> z
                = cachedInstances.putIfAbsent(bundleLocale, ref);
            if (z != null && z.get() == null) {
                cachedInstances.replace(bundleLocale, z, ref);
            }
        }
    }

    // Copy the field values from dfs to this instance.
    copyMembers(dfs, this);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:76,代码来源:DateFormatSymbols.java


注:本文中的java.util.ResourceBundle.getLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。