Skip to content

Commit 2afa00b

Browse files
committed
[breaking] i18n - Introduced Messages.keys(Locale) allowing to list available Messages keys for a given Locale.
If you implemented your own Messages implementation, it will break your code : simply provide same implementation for keys(), without fixing the Locale.
1 parent f46e2ff commit 2afa00b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

restx-i18n/src/main/java/restx/i18n/DefaultMessages.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,16 @@ public String getMessage(String key, MessageParams params, Locale locale) {
5555
}
5656

5757
@Override
58-
public Iterable<String> keys() {
59-
Optional<ResourceBundle> bundle = getBundle(Locale.ROOT);
58+
public Iterable<String> keys(Locale locale) {
59+
Optional<ResourceBundle> bundle = getBundle(locale);
6060
return bundle.isPresent() ? Ordering.natural().sortedCopy(bundle.get().keySet()) : Collections.<String>emptySet();
6161
}
6262

63+
@Override
64+
public Iterable<String> keys() {
65+
return keys(Locale.ROOT);
66+
}
67+
6368
@Override
6469
public Iterable<Entry<String, String>> entries(Locale locale) {
6570
Optional<ResourceBundle> rootBundle = getBundle(Locale.ROOT);

restx-i18n/src/main/java/restx/i18n/Messages.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
* an interpolation mechanism using a mustache like format, making it easier to use in Javascript client too.
99
*/
1010
public interface Messages {
11+
/**
12+
* Return the list of message keys available in this Messages instance, for given Locale
13+
*
14+
* @param locale the locale in which the keys should be resolved.
15+
* @return the list of keys, as an Iterable
16+
*/
17+
Iterable<String> keys(Locale locale);
18+
1119
/**
1220
* Return the list of message keys available in this Messages instance.
1321
*

0 commit comments

Comments
 (0)