Skip to content

Commit

Permalink
[JENKINS-73246] Fix text shown in unexpected locale (#9370)
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Du <i@bobdu.cc>
  • Loading branch information
BobDu committed Jun 11, 2024
1 parent 386e04c commit 0ad6657
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/model/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,10 @@ public static URL getStaticHelpUrl(StaplerRequest req, Klass<?> c, String suffix
if (url != null) return url;
url = c.getResource(base + '_' + locale.getLanguage() + ".html");
if (url != null) return url;
if (locale.getLanguage().equals("en")) {
url = c.getResource(base + ".html");
if (url != null) return url;
}
}

// default
Expand Down
19 changes: 19 additions & 0 deletions core/src/test/java/hudson/GetLocaleStaticHelpUrlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Enumeration;
import java.util.Locale;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.Issue;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.lang.Klass;

Expand Down Expand Up @@ -191,6 +192,24 @@ public void getStaticHelpUrlAcceptZhResMore() {
assertThatLocaleResourceIs(id, "help-id_zh_CN.html");
}

@Issue("JENKINS-73246")
@Test
public void getStaticHelpUrlAcceptEnFirst() {
// Accept-Language: en-US,en;q=0.9,de;q=0.8
StaplerRequest req = mockStaplerRequest(
Locale.US,
Locale.ENGLISH,
Locale.GERMAN
);

Klass klass = mockKlass(
"help-id.html",
"help-id_de.html"
);
URL id = Descriptor.getStaticHelpUrl(req, klass, "-id");
assertThatLocaleResourceIs(id, "help-id.html");
}

private StaplerRequest mockStaplerRequest(Locale... localeArr) {
StaplerRequest req = mock(StaplerRequest.class);
Enumeration<Locale> locales = Collections.enumeration(Arrays.asList(localeArr));
Expand Down

0 comments on commit 0ad6657

Please sign in to comment.