java.util.Locale.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中java.util.Locale.<init>()方法的一些代码示例,展示了Locale.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.<init>()方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:<init>

Locale.<init>介绍

[英]Constructs a new Locale using the specified language.
[中]使用指定的语言构造新的区域设置。

代码示例

代码示例来源:origin: stackoverflow.com

Locale locale = new Locale("en_US"); 
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getApplicationContext().getResources().updateConfiguration(config, null);

代码示例来源:origin: stackoverflow.com

String languageToLoad  = "en"; // your language 
Locale locale = new Locale(languageToLoad);  
Locale.setDefault(locale); 
Configuration config = new Configuration(); 
config.locale = locale; 
getBaseContext().getResources().updateConfiguration(config,  
getBaseContext().getResources().getDisplayMetrics());

代码示例来源:origin: stackoverflow.com

public void onConfigurationChanged(Configuration newConfig)
{
  super.onConfigurationChanged(newConfig);
  // Set correct language (default or chosen)
  Locale locale = new Locale(getState()); 
  Locale.setDefault(locale);
  newConfig.locale = locale;
  getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
}

代码示例来源:origin: stackoverflow.com

double amount =200.0;
Locale locale = new Locale("en", "US");      
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(locale);
System.out.println(currencyFormatter.format(amount));

代码示例来源:origin: stackoverflow.com

package com.stackoverflow.q2357315;

import java.util.Locale;

public class Test {
  public static void main(String[] args) throws Exception {
    Locale.setDefault(new Locale("lt"));
    String s = "\u00cc";
    System.out.println(s + " (" + s.length() + ")"); // Ì (1)
    s = s.toLowerCase();
    System.out.println(s + " (" + s.length() + ")"); // i̇̀ (3)
  }
}

代码示例来源:origin: xalan/xalan

throws MissingResourceException
Locale locale = Locale.getDefault();
 return (ListResourceBundle)ResourceBundle.getBundle(className, locale);
  return (ListResourceBundle)ResourceBundle.getBundle(
   className, new Locale("en", "US"));
  throw new MissingResourceException(
   "Could not load any resource bundles." + className, className, "");

代码示例来源:origin: spring-projects/spring-framework

@Test
public void dateOtherLocale() {
  Locale defaultLocale = Locale.getDefault();
  try {
    Locale.setDefault(new Locale("nl", "nl"));
    Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20);
    calendar.setTimeZone(TimeZone.getTimeZone("CET"));
    long date = calendar.getTimeInMillis();
    headers.setDate(date);
    assertEquals("Invalid Date header", "Thu, 18 Dec 2008 10:20:00 GMT", headers.getFirst("date"));
    assertEquals("Invalid Date header", date, headers.getDate());
  }
  finally {
    Locale.setDefault(defaultLocale);
  }
}

代码示例来源:origin: TeamNewPipe/NewPipe

public static Locale getPreferredLocale(Context context) {
  SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
  String languageCode = sp.getString(context.getString(R.string.content_language_key),
      context.getString(R.string.default_language_value));
  try {
    if (languageCode.length() == 2) {
      return new Locale(languageCode);
    } else if (languageCode.contains("_")) {
      String country = languageCode.substring(languageCode.indexOf("_"), languageCode.length());
      return new Locale(languageCode.substring(0, 2), country);
    }
  } catch (Exception ignored) {
  }
  return Locale.getDefault();
}

代码示例来源:origin: RipMeApp/ripme

/**
 * Gets the ResourceBundle AKA language package.
 * Used for choosing the language of the UI.
 *
 * @return Returns the default resource bundle using the language specified in the config file.
 */
public static ResourceBundle getResourceBundle(String langSelect) {
  if (langSelect == null) {
    if (!getConfigString("lang", "").equals("")) {
      String[] langCode = getConfigString("lang", "").split("_");
      LOGGER.info("Setting locale to " + getConfigString("lang", ""));
      return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control());
    }
  } else {
    String[] langCode = langSelect.split("_");
    LOGGER.info("Setting locale to " + langSelect);
    return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control());
  }
  try {
    LOGGER.info("Setting locale to default");
    return ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), new UTF8Control());
  } catch (MissingResourceException e) {
    LOGGER.info("Setting locale to root");
    return ResourceBundle.getBundle("LabelsBundle", Locale.ROOT);
  }
}

代码示例来源:origin: plutext/docx4j

/**
 * Method init
 *
 * @param languageCode
 * @param countryCode
 */
public static synchronized void init(String languageCode, String countryCode) {
  if (alreadyInitialized) {
    return;
  }
  I18n.resourceBundle =
    ResourceBundle.getBundle(
      Constants.exceptionMessagesResourceBundleBase,
      new Locale(languageCode, countryCode)
    );
  alreadyInitialized = true;
}

代码示例来源:origin: stackoverflow.com

public class MyApplication extends Application
{
 @Override
 public void onCreate()
 {
  updateLanguage(this);
  super.onCreate();
 }

 public static void updateLanguage(Context ctx)
 {
  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
  String lang = prefs.getString("locale_override", "");
  updateLanguage(ctx, lang);
 }

 public static void updateLanguage(Context ctx, String lang)
 {
  Configuration cfg = new Configuration();
  if (!TextUtils.isEmpty(lang))
   cfg.locale = new Locale(lang);
  else
   cfg.locale = Locale.getDefault();

  ctx.getResources().updateConfiguration(cfg, null);
 }
}

代码示例来源:origin: robovm/robovm

return (XResourceBundle) ResourceBundle.getBundle(resourceName, locale);
 return (XResourceBundle) ResourceBundle.getBundle(
  XSLT_RESOURCE, new Locale("en", "US"));
 throw new MissingResourceException(
  "Could not load any resource bundles.", className, "");

代码示例来源:origin: stackoverflow.com

double amount =200.0;
System.out.println(NumberFormat.getCurrencyInstance(new Locale("en", "US"))
    .format(amount));

代码示例来源:origin: stackoverflow.com

import java.util.Locale;

public class ToLocaleTest {
  public static void main(String[] args) throws Exception {
    Locale.setDefault(new Locale("lt")); //setting Lithuanian as locale
    String str = "\u00cc";
  System.out.println("Before case conversion is "+str+
" and length is "+str.length());// Ì
    String lowerCaseStr = str.toLowerCase();
  System.out.println("Lower case is "+lowerCaseStr+
" and length is "+lowerCaseStr.length());// iı`
  }
}

代码示例来源:origin: robovm/robovm

Locale locale = Locale.getDefault();
String suffix = getResourceSuffix(locale);
 return (XSLTErrorResources) ResourceBundle.getBundle(className
     + suffix, locale);
  return (XSLTErrorResources) ResourceBundle.getBundle(className,
      new Locale("en", "US"));
  throw new MissingResourceException(
   "Could not load any resource bundles.", className, "");

代码示例来源:origin: geoserver/geoserver

@Test
public void testSingleBandedCoverage_GEOS7311() throws Exception {
  Locale defaultLocale = Locale.getDefault();
  Locale.setDefault(new Locale("es", "ES"));
  testSingleBandedCoverage();
  Locale.setDefault(new Locale("fr", "FR"));
  testSingleBandedCoverage();
  Locale.setDefault(defaultLocale);
}

代码示例来源:origin: stanfordnlp/CoreNLP

public CustomDateFormatExtractor(String timePattern, String localeString) {
 Locale locale = (localeString != null)? new Locale(localeString): Locale.getDefault();
 this.timePattern = timePattern;
 builder = new FormatterBuilder();
 builder.locale = locale;
 parsePatternTo(builder, timePattern);
 textPattern = builder.toTextPattern();
}

代码示例来源:origin: stackoverflow.com

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;

public class Main extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  String languageToLoad  = "fa"; // your language
  Locale locale = new Locale(languageToLoad); 
  Locale.setDefault(locale);
  Configuration config = new Configuration();
  config.locale = locale;
  getBaseContext().getResources().updateConfiguration(config, 
   getBaseContext().getResources().getDisplayMetrics());
  this.setContentView(R.layout.main);
 }
}

代码示例来源:origin: languagetool-org/languagetool

/**
 * Gets the resource bundle for the specified language.
 * @param languageCode lowercase two-letter ISO-639 code.
 * @return the resource bundle for the specified language.
 */
public static ResourceBundle getMessages(String languageCode) {
 if (languageCode.length() > 3) {
  throw new RuntimeException("Use a character code (ISO-639 code), not a full language name: " + languageCode);
 }
 ResourceBundle messages = ResourceBundle.getBundle(
     JLanguageTool.MESSAGE_BUNDLE, new Locale(languageCode));
 return messages;
}

代码示例来源:origin: stackoverflow.com

import java.util.Locale;

public class Test {
 public static void main(String[] args) {
  Locale.setDefault(new Locale("hi", "IN"));
  System.out.printf("String: %s; Number: %d\n", 1234, 1234);
 }
}

相关文章