@Override public void onBindViewHolder(ViewHolder holder, int position) { holder.mTextView.setText(mLocales[position].getDisplayName()); }
/** * Equivalent to {@code getDisplayName(Locale.getDefault())}. */ public final String getDisplayName() { return getDisplayName(getDefault()); }
String locale = context.getResources().getConfiguration().locale.getDisplayName(); String locale = java.util.Locale.getDefault().getDisplayName();
/** * A variant of {@link #getAcceptLanguage()} that converts each * {@link java.util.Locale.LanguageRange} to a {@link Locale}. * @return the locales or an empty list * @throws IllegalArgumentException if the value cannot be converted to a locale * @since 5.0 */ public List<Locale> getAcceptLanguageAsLocales() { List<Locale.LanguageRange> ranges = getAcceptLanguage(); if (ranges.isEmpty()) { return Collections.emptyList(); } return ranges.stream() .map(range -> Locale.forLanguageTag(range.getRange())) .filter(locale -> StringUtils.hasText(locale.getDisplayName())) .collect(Collectors.toList()); }
private static String getLanguageStr(Properties props) { return getLanguage(props).getDisplayName().toLowerCase(); }
public static LocaleDescription create(Locale locale) { return create(locale.toLanguageTag(), locale.getDisplayName(Locale.ENGLISH)); }
final Locale[] availableLocales=Locale.getAvailableLocales(); for(final Locale locale : availableLocales) Log.d("Applog",":"+locale.getDisplayName()+":"+locale.getLanguage()+":" +locale.getCountry()+":values-"+locale.toString().replace("_","-r"));
/** * A variant of {@link #getAcceptLanguage()} that converts each * {@link java.util.Locale.LanguageRange} to a {@link Locale}. * @return the locales or an empty list * @throws IllegalArgumentException if the value cannot be converted to a locale * @since 5.0 */ public List<Locale> getAcceptLanguageAsLocales() { List<Locale.LanguageRange> ranges = getAcceptLanguage(); if (ranges.isEmpty()) { return Collections.emptyList(); } return ranges.stream() .map(range -> Locale.forLanguageTag(range.getRange())) .filter(locale -> StringUtils.hasText(locale.getDisplayName())) .collect(Collectors.toList()); }
public static boolean isRTL() { return isRTL(Locale.getDefault()); } public static boolean isRTL(Locale locale) { final int directionality = Character.getDirectionality(locale.getDisplayName().charAt(0)); return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT || directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC; }
@Signature(@Arg(value = "locale", nativeType = WrapLocale.class, optional = @Optional("null"))) public Memory getDisplayName(Environment env, Memory... args) { return StringMemory.valueOf(args[0].isNull() ? locale.getDisplayName() : locale.getDisplayName(args[0].toObject(WrapLocale.class).locale) ); }
@Test public void testTzParses() throws Exception { // Check that all Locales can parse the time formats we use for(final Locale locale : Locale.getAvailableLocales()) { final FastDateParser fdp= new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale); for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) { final Calendar cal= Calendar.getInstance(tz, locale); cal.clear(); cal.set(Calendar.YEAR, 2000); cal.set(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 10); final Date expected= cal.getTime(); final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale)); assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual); } } }
@Test public void testTzParses() throws Exception { // Check that all Locales can parse the time formats we use for(final Locale locale : Locale.getAvailableLocales()) { final FastDateParser fdp= new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale); for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) { final Calendar cal= Calendar.getInstance(tz, locale); cal.clear(); cal.set(Calendar.YEAR, 2000); cal.set(Calendar.MONTH, 1); cal.set(Calendar.DAY_OF_MONTH, 10); final Date expected= cal.getTime(); final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale)); Assert.assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual); } } }
@Test public void testTimeZoneStrategyPattern() { for(final Locale locale : Locale.getAvailableLocales()) { final FastDateParser parser = new FastDateParser("z", TimeZone.getDefault(), locale); final String[][] zones = DateFormatSymbols.getInstance(locale).getZoneStrings(); for(final String[] zone : zones) { for(int t = 1; t<zone.length; ++t) { final String tzDisplay = zone[t]; if (tzDisplay == null) { break; } try { parser.parse(tzDisplay); } catch(final Exception ex) { fail("'" + tzDisplay + "'" + " Locale: '" + locale.getDisplayName() + "'" + " TimeZone: " + zone[0] + " offset: " + t + " defaultLocale: " + Locale.getDefault() + " defaultTimeZone: " + TimeZone.getDefault().getDisplayName() ); } } } } }
@Test public void structuredData() { ThreadContext.put("loginId", "JohnDoe"); ThreadContext.put("ipAddress", "192.168.0.120"); ThreadContext.put("locale", Locale.US.getDisplayName()); final StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer"); msg.put("ToAccount", "123456"); msg.put("FromAccount", "123457"); msg.put("Amount", "200.00"); logger.info(MarkerManager.getMarker("EVENT"), msg); ThreadContext.clearMap(); final List<LogEvent> events = app.getEvents(); assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size()); } }
@Test public void testEventLogger() { MDC.put("loginId", "JohnDoe"); MDC.put("ipAddress", "192.168.0.120"); MDC.put("locale", Locale.US.getDisplayName()); final EventData data = new EventData(); data.setEventType("Transfer"); data.setEventId("Audit@18060"); data.setMessage("Transfer Complete"); data.put("ToAccount", "123456"); data.put("FromAccount", "123457"); data.put("Amount", "200.00"); EventLogger.logEvent(data); MDC.clear(); verify("EventLogger", "o.a.l.s.LoggerTest Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete" + Strings.LINE_SEPARATOR); }
protected void sendInfoStructuredMessage() { ThreadContext.put("loginId", "JohnDoe"); ThreadContext.put("ipAddress", "192.168.0.120"); ThreadContext.put("locale", Locale.US.getDisplayName()); final StructuredDataMessage msg = new StructuredDataMessage("Transfer@18060", "Transfer Complete", "Audit"); msg.put("ToAccount", "123456"); msg.put("FromAccount", "123457"); msg.put("Amount", "200.00"); // the msg.toString() doesn't contain the parameters of the ThreadContext, so we must use the line1 string final String str = msg.asString(null, null); sentMessages.add(str); root.info(MarkerManager.getMarker("EVENT"), msg); }
@Test public void structuredData() { ThreadContext.put("loginId", "JohnDoe"); ThreadContext.put("ipAddress", "192.168.0.120"); ThreadContext.put("locale", Locale.US.getDisplayName()); final StructuredDataMessage msg = new StructuredDataMessage("Transfer@18060", "Transfer Complete", "Audit"); msg.put("ToAccount", "123456"); msg.put("FromAccount", "123457"); msg.put("Amount", "200.00"); EventLogger.logEvent(msg); ThreadContext.clearMap(); assertEquals(1, results.size()); final String expected = "EVENT OFF Audit [Transfer@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete"; assertThat("Incorrect structured data", results.get(0), startsWith(expected)); }
@Test public void structuredData() { ThreadContext.put("loginId", "JohnDoe"); ThreadContext.put("ipAddress", "192.168.0.120"); ThreadContext.put("locale", Locale.US.getDisplayName()); final StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer"); msg.put("ToAccount", "123456"); msg.put("FromAccount", "123457"); msg.put("Amount", "200.00"); logger.info(MarkerManager.getMarker("EVENT"), msg); ThreadContext.clearMap(); assertEquals(1, results.size()); assertThat("Incorrect structured data: ", results.get(0), startsWith( "EVENT INFO Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete")); }
@Test public void structuredData() { ThreadContext.put("loginId", "JohnDoe"); ThreadContext.put("ipAddress", "192.168.0.120"); ThreadContext.put("locale", Locale.US.getDisplayName()); final StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer"); msg.put("ToAccount", "123456"); msg.put("FromAccount", "123457"); msg.put("Amount", "200.00"); logger.info(MarkerManager.getMarker("EVENT"), msg); ThreadContext.clearMap(); final List<LogEvent> events = app.getEvents(); assertEventCount(events, 1); }
@Test public void testEvents() { ThreadContext.put("loginId", "JohnDoe"); ThreadContext.put("ipAddress", "192.168.0.120"); ThreadContext.put("locale", Locale.US.getDisplayName()); final TransferMessage msg = new TransferMessage(); msg.put("ToAccount", "123456"); msg.put("FromAccount", "123457"); msg.put("Amount", "200.00"); EventLogger.logEvent(msg); msg.setCompletionStatus("Transfer Complete"); EventLogger.logEvent(msg); ThreadContext.clearMap(); // TODO: do something with the results }