use of java.util.Locale in project morphia by mongodb.
the class LocaleConverterTest method shouldEncodeAndDecodeBuiltInLocale.
@Test
public void shouldEncodeAndDecodeBuiltInLocale() throws Exception {
// given
LocaleConverter converter = new LocaleConverter();
Locale expectedLocale = Locale.CANADA_FRENCH;
// when
Locale decodedLocale = (Locale) converter.decode(Locale.class, converter.encode(expectedLocale));
// then
assertThat(decodedLocale, is(expectedLocale));
}
use of java.util.Locale in project jersey by jersey.
the class LocaleProviderTest method testFromString.
@Test
public void testFromString() throws Exception {
final LocaleProvider instance = new LocaleProvider();
assertEquals(new Locale("en"), instance.fromString("en"));
assertEquals(new Locale("en", "us"), instance.fromString("en-us"));
}
use of java.util.Locale in project jersey by jersey.
the class LocaleProviderTest method testToString.
@Test
public void testToString() {
final LocaleProvider instance = new LocaleProvider();
assertEquals("en", instance.toString(new Locale("en")));
assertEquals("en-US", instance.toString(new Locale("en", "us")));
}
use of java.util.Locale in project languagetool by languagetool-org.
the class ResourceBundleTools method getMessageBundle.
/**
* Gets the ResourceBundle (i18n strings) for the given user interface language.
*/
static ResourceBundle getMessageBundle(Language lang) {
try {
ResourceBundle bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocaleWithCountryAndVariant());
if (!isValidBundleFor(lang, bundle)) {
bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocale());
if (!isValidBundleFor(lang, bundle)) {
// happens if 'xx' is requested but only a MessagesBundle_xx_YY.properties exists:
Language defaultVariant = lang.getDefaultLanguageVariant();
if (defaultVariant != null && defaultVariant.getCountries().length > 0) {
Locale locale = new Locale(defaultVariant.getShortCode(), defaultVariant.getCountries()[0]);
bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, locale);
}
}
}
ResourceBundle fallbackBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH);
return new ResourceBundleWithFallback(bundle, fallbackBundle);
} catch (MissingResourceException e) {
return ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH);
}
}
use of java.util.Locale in project storm by apache.
the class ConsolePreparableReporter method prepare.
@Override
public void prepare(MetricRegistry metricsRegistry, Map stormConf) {
LOG.debug("Preparing...");
ConsoleReporter.Builder builder = ConsoleReporter.forRegistry(metricsRegistry);
builder.outputTo(System.out);
Locale locale = MetricsUtils.getMetricsReporterLocale(stormConf);
if (locale != null) {
builder.formattedFor(locale);
}
TimeUnit rateUnit = MetricsUtils.getMetricsRateUnit(stormConf);
if (rateUnit != null) {
builder.convertRatesTo(rateUnit);
}
TimeUnit durationUnit = MetricsUtils.getMetricsDurationUnit(stormConf);
if (durationUnit != null) {
builder.convertDurationsTo(durationUnit);
}
reporter = builder.build();
}
Aggregations