Locale Flashcards

1
Q

How do we create new locale?

A

Using Locale util.
Locale.getDefault()
Locale locale = new Locale(“hr”), new Locale(“hr”,”HR”)
Locale.GERMAN
Locale.GERMANY
Local.Builder()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do we set default categories for localization?

A

Display -> Locale.setDefault(Category.DISPLAY, german)
Format -> Locale.setDefault(Category.FORMAT, german)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do we format number using locale?

A

Using NumberFormat class.

NumberFormat.getIntegerInstance(Locale.US);
NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat.getNumberInstance(Locale.US);
NumberFormat.getPercentInstance(Locale.US);
NumberFormat.getCompactNumberInstance(Locale.US, NumberFormat.Style.SHORT);
NumberFormat.getInstance();

Formatter is then used to .format() some number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does CompactNumberFormat do?

A

It formats number with locale in context in several different ways: 1,000,000.00 into 1 million.
Formats are defined by NumberFormat.Style, for eg. NumberFormat.Style.SHORT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do we parse numbers in locale formatting?

A

Each NumberFormat instance has .parse() method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do we format dates in locale?

A

DateTimeFormatter.ofLocalizedDate(FormatStyle)
DateTimeFormatter.ofLocalizedTime()
DateTimeFormatter.ofLocalizedDateTime()

Formatter is then used to .format() some date.

Also, DateTimeFormatter.withLocale(locale).format(date) can be used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

ResourceBundle, how do we use it?

A

ResourceBundle.getBundle(“Name”, locale);
or
ResourceBundle.getBundle(“Name”);

Then we rs.getString(“key”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How ResoruceBundle resolves properties files?

A

If locale is defined as “hr_HR”:

Wanted:
Name_hr_HR.properties
Name_hr.properties

Default:
Name_us_US.properties
Name_us.properties

Name.properties

MissingResourceException

If wanted locale is defined as “hr”:
Name_hr.properties
Name_us.properties
Name.properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do we format messages from string?

A

key.in.properties=Hello, {0} and {1}
MessageFormat.format(string, “Tammy”, “Henry”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do we set properties?

A

We instantiate new Properties();
pros.setProperty(“name”, “Peter”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly