Skip to content

Commit

Permalink
add optional Locale param for sorting Collator
Browse files Browse the repository at this point in the history
  • Loading branch information
tltv committed Sep 13, 2024
1 parent 79503e4 commit 1ad4dd5
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,31 @@ public static Map<String, AvailableViewInfo> collectMenuItems() {
* @return ordered routes with view information
*/
public static List<AvailableViewInfo> collectMenuItemsList() {
// en-US is used by default here to match with Hilla's
// createMenuItems.ts sorting algorithm.
return collectMenuItemsList(Locale.forLanguageTag("en-US"));
}

/**
* Collect ordered list of views with menu annotation for automatic menu
* population. All client views are collected and any accessible server
* views.
*
* @param locale
* locale to use for ordering. null for default locale.
* @return ordered routes with view information
*/
public static List<AvailableViewInfo> collectMenuItemsList(Locale locale) {
return collectMenuItems().entrySet().stream().map(entry -> {
AvailableViewInfo value = entry.getValue();
return new AvailableViewInfo(value.title(), value.rolesAllowed(),
value.loginRequired(), entry.getKey(), value.lazy(),
value.register(), value.menu(), value.children(),
value.routeParameters(), value.flowLayout());
}).sorted(getMenuOrderComparator(
Collator.getInstance(Locale.forLanguageTag("en-US")))).toList();
(locale != null ? Collator.getInstance(locale)
: Collator.getInstance())))
.toList();
}

/**
Expand Down

0 comments on commit 1ad4dd5

Please sign in to comment.