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

Extend DefaultI18NProvider for Spring #17836

Closed
Tracked by #4379
caalador opened this issue Oct 16, 2023 · 1 comment · Fixed by #17933
Closed
Tracked by #4379

Extend DefaultI18NProvider for Spring #17836

caalador opened this issue Oct 16, 2023 · 1 comment · Fixed by #17933

Comments

@caalador
Copy link
Contributor

For spring there should be a Bean defined for DefaultI18NProvider that would check for default translations using ResourcePatternResolver e.g. resourcePatternResolver.getResources("classpath:**/vaadin-i18n/*.properties);

Code would be something like:

@Bean
@ConditionalOnMissingBean(value = I18NProvider.class)
public DefaultI18NProvider vaadinI18nProvider() {
  Resource[] translations = resourcePatternResolver.getResources("classpath:**/vaadin-i18n/*.properties);
  if(translations.length > 0) {
    List<Locale> locales = I18NUtil.collectLocalesFromFiles(Arrays.stream(translations).map(Resource::getFile).collect(Collectors.toList()));
    return new DefaultI18NProvider(locales );
  }
  return null;
}

I18NUtil needs extraction of the collectLocalesFromFiles.

Continuation of #17823 and #5917

@mshabarov mshabarov added the I18N label Oct 24, 2023
@mshabarov mshabarov moved this to 🪵Product backlog in Vaadin Flow ongoing work (Vaadin 10+) Oct 24, 2023
@mshabarov mshabarov moved this from 🪵Product backlog to 🟢Ready to Go in Vaadin Flow ongoing work (Vaadin 10+) Oct 25, 2023
@tltv tltv self-assigned this Oct 25, 2023
@tltv tltv moved this from 🟢Ready to Go to ⚒️ In progress in Vaadin Flow ongoing work (Vaadin 10+) Oct 25, 2023
tltv added a commit that referenced this issue Oct 26, 2023
Extends DefaultI18NProvider (#5917) for Spring. `VaadinApplicationConfiguration` defines `DefaultI18NProvider` bean and initializes it with locales based on translation properties files found in the classpath under '/vaadin-i18n' path.

Fixes: #17836
mshabarov pushed a commit that referenced this issue Oct 30, 2023
* feat: add default I18N provider bean for Spring

Extends DefaultI18NProvider (#5917) for Spring. `VaadinApplicationConfiguration` defines `DefaultI18NProvider` bean and initializes it with locales based on translation properties files found in the classpath under '/vaadin-i18n' path.

Fixes: #17836

* chore: fixed test names

* chore: fixed JavaDoc

* chore: fixed serialization

* chore: removed Logger field

* Added Condition and property for DefaultI18NProvider bean

Added `vaadin.i18n.location-pattern` property. Added Conditional annotation with Condition implemented by DefaultI18NProviderFactory. Also moved location pattern to create(String) method.

* Changed DefaultI18NProviderFactory#create(String) to static

---------

Co-authored-by: caalador <[email protected]>
@github-project-automation github-project-automation bot moved this from ⚒️ In progress to Done in Vaadin Flow ongoing work (Vaadin 10+) Oct 30, 2023
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.3.0.alpha4 and is also targeting the upcoming stable 24.3.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

4 participants