Skip to content

Commit

Permalink
[JENKINS-73246] Fix text shown in unexpected locale (jenkinsci#9370)
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Du <[email protected]>
(cherry picked from commit 0ad6657)
  • Loading branch information
BobDu authored and krisstern committed Jun 24, 2024
1 parent 3633ce3 commit 62ba922
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 62ba922

Please sign in to comment.