Skip to content

Commit

Permalink
Move method body
Browse files Browse the repository at this point in the history
  • Loading branch information
André Laugks committed Apr 26, 2024
1 parent 4d69d77 commit 926640c
Showing 1 changed file with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ public XliffTranslationMessageSource build() {

@Nullable
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
return this.format(
this.internalMessageWithDefaultMessage(code, defaultMessage, locale),
args
);
String translation = this.catalogHandler.get(locale, code);
if (translation != null) {
return this.format(translation, args);
}
return this.format(defaultMessage, args);
}

public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
String translation = this.internalMessage(code, locale);
String translation = this.catalogHandler.get(locale, code);
if (translation != null) {
return this.format(translation, args);
}
Expand All @@ -130,7 +131,7 @@ public String getMessage(MessageSourceResolvable resolvable, Locale locale) thro
String[] codes = resolvable.getCodes();
if (codes != null) {
for (String code : codes) {
String translation = this.internalMessage(code, locale);
String translation = this.catalogHandler.get(locale, code);
if (translation != null) {
return this.format(translation, resolvable.getArguments());
}
Expand All @@ -146,22 +147,6 @@ public String getMessage(MessageSourceResolvable resolvable, Locale locale) thro
throw new NoSuchMessageException(codes != null && codes.length > 0 ? codes[codes.length - 1] : "", locale);
}

private String internalMessage(String code, Locale locale) throws NoSuchMessageException {
return this.findInCatalog(locale, code);
}

private String internalMessageWithDefaultMessage(String code, @Nullable String defaultMessage, Locale locale) {
String translation = this.findInCatalog(locale, code);
if (translation != null) {
return translation;
}
return defaultMessage;
}

private String findInCatalog(Locale locale, String code) {
return this.catalogHandler.get(locale, code);
}

private String format(@Nullable String message, @Nullable Object[] args) {
if (message != null && args != null && args.length > 0) {
return new MessageFormat(message).format(args);
Expand Down

0 comments on commit 926640c

Please sign in to comment.