Skip to content
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 11 commits into from
Oct 4, 2024
Merged

[FOLSPRINGS-169] Additional i18n methods #187

merged 11 commits into from
Oct 4, 2024

Conversation

ncovercash
Copy link
Member

@ncovercash ncovercash commented Oct 3, 2024

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-specific ULocale which allows us to pass regular locale information (lang/region), plus parameters (including the timezone).

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)
    • ⚠️ replaces String format(String key, Object... args)
    • non-breaking since TranslationMap is never exposed for consumption outside this library
  • String formatString(ZoneId zone, String format, Object... args)

TODOS and Open Questions

  • Update NEWS.md.

NEWS.md Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Oct 4, 2024

@ncovercash ncovercash merged commit b9306f4 into master Oct 4, 2024
4 checks passed
@ncovercash ncovercash deleted the folsprings-169 branch October 4, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants