-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FOLSPRINGS-169] Additional i18n methods #187
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ncovercash
requested review from
psmagin,
OleksiiKuzminov,
TarasSpashchenko,
dmtkachenko,
oliinyko,
viacheslavkol,
mukhiddin-yusuf,
bvsharp,
kjain110 and
mweaver-ebsco
October 3, 2024 21:26
kjain110
approved these changes
Oct 3, 2024
folio-spring-i18n/src/main/java/org/folio/spring/i18n/model/TranslationMap.java
Outdated
Show resolved
Hide resolved
folio-spring-i18n/src/main/java/org/folio/spring/i18n/model/TranslationMap.java
Outdated
Show resolved
Hide resolved
folio-spring-i18n/src/main/java/org/folio/spring/i18n/service/TranslationService.java
Outdated
Show resolved
Hide resolved
bvsharp
approved these changes
Oct 4, 2024
Quality Gate passedIssues Measures |
psmagin
approved these changes
Oct 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Jira FOLSPRINGS-169
Purpose
This adds a series of convenience methods for i18n, particularly for providing custom locales and timezones. Locales are typically guessed by the request context, however, this is not always available (for example, in background tasks), so a failsafe is nice.
Additionally, there is currently no way to get a user's timezone based on headers, so we don't have a way for
folio-spring-i18n
to guess the user's timezone. As such, we are now also providing methods for custom timezones to be passed in (and, if none is provided, the system time will be used, as was the previous default).It may be worthwhile to consider API calls to mod-configuration to get the tenant's locale settings in the future, but that is well outside the scope of this ticket.
Approach
The timezone part was a bit tricky, as
icu4j
doesn't readily expose setters for this when formatting messages. However, we can pass it an icu-specificULocale
which allows us to pass regular locale information (lang/region), plus parameters (including thetimezone
).Full list of added methods:
TranslationService
String format(Collection<Locale> locales, String key, Object... args)
String format(ZoneId zone, String key, Object... args)
String format(Collection<Locale> locales, ZoneId zone, String key, Object... args)
boolean hasKey(String key)
boolean hasKey(Collection<Locale> locales, String key)
TranslationMap
boolean hasKey(String key)
String format(ZoneId zone, String key, Object... args)
String format(String key, Object... args)
TranslationMap
is never exposed for consumption outside this libraryString formatString(ZoneId zone, String format, Object... args)
TODOS and Open Questions