Unverified Commit f88cb3da authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

Merge pull request #3600 from jumpserver/dev_i18n

[Update] dateRange插件支持i18n
parents 05adb4e9 9f42dfb2
......@@ -1237,7 +1237,7 @@ function toSafeDateISOStr(s) {
function toSafeLocalDateStr(d) {
var date = safeDate(d);
var date_s = date.toLocaleString(navigator.language, {hour12: false});
var date_s = date.toLocaleString(getUserLang(), {hour12: false});
return date_s.split("/").join('-')
}
......@@ -1257,7 +1257,7 @@ function getTimeUnits(u) {
"m": "分",
"s": "秒",
};
if (navigator.language === "zh-CN") {
if (getUserLang() === "zh-CN") {
return units[u]
}
return u
......@@ -1395,6 +1395,16 @@ function showCeleryTaskLog(taskId) {
window.open(url, '', 'width=900,height=600')
}
function getUserLang(){
let userLangZh = document.cookie.indexOf('django_language=zh');
if (userLangZh !== -1){
return 'zh-CN'
}
else{
return 'en-US'
}
}
function initDateRangePicker(selector, options) {
if (!options) {
options = {}
......@@ -1408,6 +1418,15 @@ function initDateRangePicker(selector, options) {
daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],//汉化处理
monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
};
var enLocale = {
format: "YYYY-MM-DD HH:mm",
separator: " - ",
applyLabel: "Apply",
cancelLabel: "Cancel",
resetLabel: "Reset",
daysOfWeek: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
};
var defaultOption = {
singleDatePicker: true,
showDropdowns: true,
......@@ -1415,10 +1434,13 @@ function initDateRangePicker(selector, options) {
timePicker24Hour: true,
autoApply: true,
};
var userLang = navigator.language || navigator.userLanguage;
if (userLang.indexOf('zh') !== -1) {
if (getUserLang() === 'zh-CN') {
defaultOption.locale = zhLocale;
}
else{
// en-US
defaultOption.locale = enLocale;
}
options = Object.assign(defaultOption, options);
return $(selector).daterangepicker(options);
}
......
......@@ -7,7 +7,7 @@
<script src="{% static "js/plugins/toastr/toastr.min.js" %}"></script>
<script src="{% static "js/inspinia.js" %}"></script>
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<script src="{% static "js/jumpserver.js" %}?v=6"></script>
<script src="{% static "js/jumpserver.js" %}?v=7"></script>
<script src="{% static 'js/plugins/select2/select2.full.min.js' %}"></script>
<script src="{% static 'js/plugins/select2/i18n/zh-CN.js' %}"></script>
<script>
......@@ -18,9 +18,6 @@ $(document).ready(function(){
if ($('.tooltip')[0]) {
$('.tooltip').tooltip();
}
var userLang = navigator.language || navigator.userLanguage;
if (userLang.indexOf('zh') !== -1) {
$.fn.select2.defaults.set('language', 'zh-CN')
}
$.fn.select2.defaults.set('language', getUserLang())
});
</script>
......@@ -86,7 +86,7 @@ $(document).ready(function () {
forceParse: false,
calendarWeeks: true,
autoclose: true,
language: navigator.language || "en",
language: getUserLang(),
};
dateFromRef.datepicker(options).on("changeDate", function () {
var value = $(this).val() + ' 0:0:0';
......
......@@ -193,7 +193,7 @@ $(document).ready(function() {
forceParse: false,
calendarWeeks: true,
autoclose: true,
language: navigator.language || "en",
language: getUserLang(),
};
dateFromRef.datepicker(options).on("changeDate", function () {
if (!$(this).val()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment