Skip to content

Commit

Permalink
Intercept getLocales() (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesbusy authored Jun 10, 2024
1 parent 2868c41 commit 2123707
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
<properties>
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/locale-plugin</gitHubRepo>
<jenkins.version>2.440.3</jenkins.version>
<jenkins.version>2.452.1</jenkins.version>
<configuration-as-code.version>1810.v9b_c30a_249a_4c</configuration-as-code.version>
<spotless.check.skip>false</spotless.check.skip>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.440.x</artifactId>
<artifactId>bom-2.452.x</artifactId>
<version>3120.v4d898e1e9fc4</version>
<type>pom</type>
<scope>import</scope>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/hudson/plugins/locale/LocaleFilter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package hudson.plugins.locale;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.NoSuchElementException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
Expand Down Expand Up @@ -33,6 +35,29 @@ public Locale getLocale() {
// Force locale to configured default, ignore request' Accept-Language header
return Locale.getDefault();
}

@Override
public Enumeration<Locale> getLocales() {
// Create a custom Enumeration with only the default locale
return new Enumeration<Locale>() {
private boolean hasMoreElements = true;

@Override
public boolean hasMoreElements() {
return hasMoreElements;
}

@Override
public Locale nextElement() {
if (hasMoreElements) {
hasMoreElements = false;
return getLocale();
} else {
throw new NoSuchElementException();

Check warning on line 56 in src/main/java/hudson/plugins/locale/LocaleFilter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 42-56 are not covered by tests
}
}
};
}
};
}
}
Expand Down

0 comments on commit 2123707

Please sign in to comment.