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

[JENKINS-73246] Fix text shown in unexpected locale #9370

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading