Skip to content

Commit

Permalink
[breaking] i18n - Introduced Messages.keys(Locale) allowing to list a…
Browse files Browse the repository at this point in the history
…vailable 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.
  • Loading branch information
fcamblor committed Nov 21, 2016
1 parent f46e2ff commit 2afa00b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions restx-i18n/src/main/java/restx/i18n/DefaultMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ public String getMessage(String key, MessageParams params, Locale locale) {
}

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

@Override
public Iterable<String> keys() {
return keys(Locale.ROOT);
}

@Override
public Iterable<Entry<String, String>> entries(Locale locale) {
Optional<ResourceBundle> rootBundle = getBundle(Locale.ROOT);
Expand Down
8 changes: 8 additions & 0 deletions restx-i18n/src/main/java/restx/i18n/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
* an interpolation mechanism using a mustache like format, making it easier to use in Javascript client too.
*/
public interface Messages {
/**
* Return the list of message keys available in this Messages instance, for given Locale
*
* @param locale the locale in which the keys should be resolved.
* @return the list of keys, as an Iterable
*/
Iterable<String> keys(Locale locale);

/**
* Return the list of message keys available in this Messages instance.
*
Expand Down

0 comments on commit 2afa00b

Please sign in to comment.