未验证 提交 faa5d3b3 编写于 作者: Z Zhao Xiaojie 提交者: GitHub

Merge pull request #80 from LinuxSuRen/community-page

Add Chinese Community page
package io.jenkins.plugins.localization_zh_cn;
import hudson.Extension;
import hudson.model.PageDecorator;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import java.util.Locale;
@Extension
public class CommunityDecorator extends PageDecorator {
public boolean isCurrentLanguage() {
StaplerRequest req = Stapler.getCurrentRequest();
if(req == null) {
return false;
}
String languages = req.getHeader("Accept-Language");
if(languages != null) {
return languages.startsWith(Locale.SIMPLIFIED_CHINESE.toString())
|| languages.startsWith("zh-CN");
}
return false;
}
}
package io.jenkins.plugins.localization_zh_cn;
import hudson.Extension;
import hudson.model.UnprotectedRootAction;
import org.jenkinsci.Symbol;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
@Extension
@Symbol("chinese")
public class CommunityPage implements UnprotectedRootAction {
@CheckForNull
@Override
public String getIconFileName() {
return null;
}
@Nonnull
@Override
public String getDisplayName() {
return "Jenkins Chinese Community";
}
@CheckForNull
@Override
public String getUrlName() {
return "chinese";
}
}
<?jelly escape-by-default='true'?>
<div>
Jenkins 及其插件的简体中文语言包
Jenkins Core 及其插件的简体中文语言包,由 <a href="https://jenkins-zh.cn/about" target="_blank">Jenkins 中文社区</a>维护
</div>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<j:if test="${it.isCurrentLanguage()}">
<span>
<a href="${rootURL}/chinese">Jenkins 中文社区</a>
</span>
</j:if>
</j:jelly>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout norefresh="true" permission="${app.READ}">
<st:include page="sidepanel.jelly" it="${app}"/>
<l:main-panel>
<div style="margin:10px;">
Jenkins Core 及其插件的简体中文语言包,由 <a href="https://jenkins-zh.cn/about" target="_blank">Jenkins 中文社区</a>维护。我们致力于给每一位 Jenkins 的中文用户带来更好的体验,并非常欢迎您反馈任何建议和意见。
</div>
<div style="margin:10px;">
我们会在 Jenkins 社区官方微信公众号上发布以下资讯信息:
<li>社区的线上以及线下活动,例如:Jenkins Meetup</li>
<li>官方博客文章</li>
<li>CI/CD 相关的技术文章(原创、翻译),案例分享</li>
<li>版本更新发布</li>
<img width="300px" height="300px" src="${rootURL}/plugin/localization-zh-cn/images/jenkins-wechat.png" alt="Jenkins 微信公众号二维码"/>
</div>
</l:main-panel>
</l:layout>
</j:jelly>
\ No newline at end of file
package io.jenkins.plugins.localization_zh_cn;
import com.gargoylesoftware.htmlunit.ElementNotFoundException;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.util.UrlUtils;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.net.URL;
import java.util.Locale;
import static org.junit.Assert.*;
public class CommunityPageTest {
@Rule
public JenkinsRule rule = new JenkinsRule();
@Test
public void indexPage() throws IOException, SAXException {
JenkinsRule.WebClient client = rule.createWebClient();
client.goTo("chinese");
}
@Test
public void locale() throws IOException, SAXException {
JenkinsRule.WebClient client = rule.createWebClient();
URL rootURL = UrlUtils.toUrlUnsafe(client.getContextPath());
WebRequest webRequest = new WebRequest(rootURL);
webRequest.setAdditionalHeader("Accept-Language", Locale.ENGLISH.toString());
// for English locale
HtmlPage page = client.getPage(webRequest);
HtmlAnchor anchor = null;
try {
page.getAnchorByText("Jenkins 中文社区");
} catch (ElementNotFoundException e) {
// should throw an exception here
}
// for Chinese locale
webRequest.removeAdditionalHeader("Accept-Language");
webRequest.setAdditionalHeader("Accept-Language", Locale.SIMPLIFIED_CHINESE.toString());
page = client.getPage(webRequest);
anchor = page.getAnchorByText("Jenkins 中文社区");
assertNotNull(anchor);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册