-
Notifications
You must be signed in to change notification settings - Fork 17
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-57456] User language prefer setting support #8
Open
LinuxSuRen
wants to merge
15
commits into
jenkinsci:main
Choose a base branch
from
LinuxSuRen:user-prefer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
58b8e0f
[JENKINS-57456] User language prefer setting support
LinuxSuRen f473cbe
Add test case for user prefer language setting
LinuxSuRen 9684b99
Use a simpler field name
LinuxSuRen cf162dd
Property might be null
LinuxSuRen 5b7d64f
Update src/main/java/hudson/plugins/locale/PluginImpl.java
LinuxSuRen df99757
Update src/main/java/hudson/plugins/locale/LocaleFilter.java
LinuxSuRen 9ad95d7
Add reference of user perference language
LinuxSuRen 3ff4a53
Add language cache support
LinuxSuRen 5aff30c
Fix the test cases
LinuxSuRen 7e223cd
Merge branch 'master' into user-prefer
LinuxSuRen a35e846
Fix the unit test fails
LinuxSuRen 83c0488
Merge branch 'user-prefer' of github.com:LinuxSuRen/locale-plugin int…
LinuxSuRen d36e0aa
Update README.md
LinuxSuRen e16f9f1
Update README.md
LinuxSuRen 2853483
Add a symbol for simplify CASC case
LinuxSuRen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
<name>Locale plugin</name> | ||
<url>https://github.com/jenkinsci/locale-plugin</url> | ||
|
||
<parent> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>plugin</artifactId> | ||
|
@@ -57,7 +57,15 @@ | |
<developerConnection>scm:git:ssh://[email protected]/jenkinsci/locale-plugin.git</developerConnection> | ||
<url>https://github.com/jenkinsci/locale-plugin</url> | ||
<tag>HEAD</tag> | ||
</scm> | ||
</scm> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jenkins-ci</groupId> | ||
<artifactId>symbol-annotation</artifactId> | ||
<version>1.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/hudson/plugins/locale/user/UserLocaleProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package hudson.plugins.locale.user; | ||
|
||
import hudson.Extension; | ||
import hudson.model.User; | ||
import hudson.model.UserProperty; | ||
import hudson.model.UserPropertyDescriptor; | ||
import hudson.plugins.locale.Messages; | ||
import hudson.plugins.locale.PluginImpl; | ||
import net.sf.json.JSONObject; | ||
import org.jenkinsci.Symbol; | ||
import org.jvnet.localizer.LocaleProvider; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import java.util.Locale; | ||
|
||
public class UserLocaleProperty extends UserProperty { | ||
private String localeCode; | ||
|
||
private Locale locale; // for the cache purpose | ||
|
||
public UserLocaleProperty(String localeCode) { | ||
this.localeCode = localeCode; | ||
} | ||
|
||
public Locale getLocale() { | ||
return locale; | ||
} | ||
|
||
public String getLocaleCode() { | ||
return localeCode; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setLocaleCode(String localeCode) { | ||
try { | ||
locale = PluginImpl.parse(localeCode); | ||
} catch (IllegalArgumentException e) { | ||
// ignore this exception | ||
} | ||
this.localeCode = localeCode; | ||
} | ||
|
||
@Extension | ||
LinuxSuRen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Symbol("userLocale") | ||
public static final class DescriptorImpl extends UserPropertyDescriptor { | ||
public String getDisplayName() { | ||
return Messages.locale(); | ||
} | ||
|
||
public UserProperty newInstance(User user) { | ||
return new UserLocaleProperty(LocaleProvider.getLocale().toString()); | ||
} | ||
|
||
@Override | ||
public UserProperty newInstance(StaplerRequest req, JSONObject formData) throws FormException { | ||
return new UserLocaleProperty(formData.optString("locale")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
locale=Locale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/resources/hudson/plugins/locale/PluginImpl/config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
description=Ignore browser preference and force this language to all users | ||
description=Ignore browser preference and force this language to all users | ||
userPreferDescription=Allow all users have their own language setting |
6 changes: 6 additions & 0 deletions
6
src/main/resources/hudson/plugins/locale/user/UserLocaleProperty/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:entry title="${%Language}"> | ||
<f:textbox field="localeCode" /> | ||
</f:entry> | ||
</j:jelly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package hudson.plugins.locale; | ||
|
||
import hudson.model.Item; | ||
import hudson.model.User; | ||
import hudson.plugins.locale.user.UserLocaleProperty; | ||
import jenkins.model.Jenkins; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.MockAuthorizationStrategy; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class UserLocaleTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void differentUsers() throws Exception { | ||
j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); | ||
MockAuthorizationStrategy authorizationStrategy = new MockAuthorizationStrategy(); | ||
authorizationStrategy.grant(Jenkins.READ).onRoot().toEveryone(); | ||
authorizationStrategy.grant(Item.READ).everywhere().to("bob"); | ||
authorizationStrategy.grant(Item.READ).everywhere().to("alice"); | ||
j.jenkins.setAuthorizationStrategy(authorizationStrategy); | ||
|
||
PluginImpl plugin = (PluginImpl) j.jenkins.getPlugin("locale"); | ||
plugin.setAllowUserPreferences(true); | ||
|
||
// test for zh_CN user | ||
User userBob = User.get("bob", true, null); | ||
UserLocaleProperty userLocaleProperty = userBob.getProperty(UserLocaleProperty.class); | ||
userLocaleProperty.setLocaleCode("zh_CN"); | ||
|
||
JenkinsRule.WebClient wc = j.createWebClient().login("bob"); | ||
String language = wc.goTo("", "text/html") | ||
.getWebResponse().getResponseHeaderValue("X-Jenkins-Language"); | ||
assertEquals("zh_CN", language); | ||
|
||
// test for en user | ||
User userAlice = User.get("alice", true, null); | ||
userLocaleProperty = userAlice.getProperty(UserLocaleProperty.class); | ||
userLocaleProperty.setLocaleCode("en"); | ||
|
||
wc = j.createWebClient().login("alice"); | ||
language = wc.goTo("", "text/html") | ||
.getWebResponse().getResponseHeaderValue("X-Jenkins-Language"); | ||
assertEquals("en", language); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Admins may want to enforce the locale on the instance. E.g. it would be my approach