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

order const. param to ResourceBundleMessageSource #11560

Open
wants to merge 1 commit into
base: 4.7.x
Choose a base branch
from

Conversation

sdelamo
Copy link
Contributor

@sdelamo sdelamo commented Jan 31, 2025

This pull-request adds a order constructor parameter to ResourceBundleMessageSource. it is used to override the Ordered::getOrder. Currently, users which defined a MessageSource with ResourceBundleMessageSource will need to customize the `order with something like:

    @Factory
    static class MessageSourceFactory {

        @Singleton
        MessageSource createMessageSource() {
            return new MessageSource() {
                private final MessageSource delegate = new ResourceBundleMessageSource("i18n.messages");

                @Override
                public @NonNull Optional<String> getRawMessage(@NonNull String code, @NonNull MessageContext context) {
                    return delegate.getRawMessage(code, context);
                }

                @Override
                public @NonNull String interpolate(@NonNull String template, @NonNull MessageContext context) {
                    return delegate.interpolate(template, context);
                }

                @Override
                public int getOrder() {
                    return HIGHEST_PRECEDENCE;
                }
            };
        }
    }

after this PR they will do:

    @Factory
    static class MessageSourceFactory {

        @Singleton
        MessageSource createMessageSource() {
            return new ResourceBundleMessageSource("i18n.messages", HIGHEST_PRECEDENCE);
        }
    }

@sdelamo sdelamo added the type: improvement A minor improvement to an existing feature label Jan 31, 2025
@sdelamo sdelamo requested a review from dstepanov January 31, 2025 11:55
This pull-request adds a `order` constructor parameter to `ResourceBundleMessageSource`. it is used to override the `Ordered::getOrder`. Currently, users which defined a MessageSource with cannot customize the `order`

```
    @factory
    static class MessageSourceFactory {

        @singleton
        MessageSource createMessageSource() {
            return new MessageSource() {
                private final MessageSource delegate = new ResourceBundleMessageSource("i18n.messages");

                @OverRide
                public @nonnull Optional<String> getRawMessage(@nonnull String code, @nonnull MessageContext context) {
                    return delegate.getRawMessage(code, context);
                }

                @OverRide
                public @nonnull String interpolate(@nonnull String template, @nonnull MessageContext context) {
                    return delegate.interpolate(template, context);
                }

                @OverRide
                public int getOrder() {
                    return HIGHEST_PRECEDENCE;
                }
            };
        }
    }
```
@sdelamo sdelamo force-pushed the messages-source-not-default branch from e2f4fac to bbdc1e8 Compare January 31, 2025 11:57
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
66.7% Coverage on New Code (required ≥ 70%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant