From b9c59c454d68e35708f64703a423930b99075cab Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Fri, 19 Aug 2016 11:49:24 +0800 Subject: Add support of i18n with related patches and support "en" and "zh" locales for now --- public/css/cover.css | 4 +++ public/js/cover.js | 2 +- public/js/locale.js | 24 +++++++++++++ public/views/body.ejs | 60 ++++++++++++++++---------------- public/views/header.ejs | 52 ++++++++++++++-------------- public/views/help-modal.ejs | 76 ++++++++++++++++++++--------------------- public/views/index.ejs | 69 ++++++++++++++++++++----------------- public/views/refresh-modal.ejs | 18 +++++----- public/views/revision-modal.ejs | 8 ++--- public/views/signin-modal.ejs | 14 ++++---- 10 files changed, 180 insertions(+), 147 deletions(-) create mode 100644 public/js/locale.js (limited to 'public') diff --git a/public/css/cover.css b/public/css/cover.css index bde3ec7c..ca0c6027 100644 --- a/public/css/cover.css +++ b/public/css/cover.css @@ -329,6 +329,10 @@ input { vertical-align: middle !important; } +select { + color: black; +} + @media (max-width: 768px) { span.ui-or { display: block; diff --git a/public/js/cover.js b/public/js/cover.js index c97bd256..f3533826 100644 --- a/public/js/cover.js +++ b/public/js/cover.js @@ -291,7 +291,7 @@ $(".ui-logout").click(function () { var filtertags = []; $(".ui-use-tags").select2({ - placeholder: 'Select tags...', + placeholder: $(".ui-use-tags").attr('placeholder'), multiple: true, data: function () { return { diff --git a/public/js/locale.js b/public/js/locale.js new file mode 100644 index 00000000..6fe7fdb6 --- /dev/null +++ b/public/js/locale.js @@ -0,0 +1,24 @@ +var lang = "en"; +var userLang = navigator.language || navigator.userLanguage; +var userLangCode = userLang.split('-')[0]; +var userCountryCode = userLang.split('-')[1]; +var locale = $('.ui-locale'); +var supportLangs = []; +$(".ui-locale option").each(function() { + supportLangs.push($(this).val()); +}); +if (Cookies.get('locale')) { + lang = Cookies.get('locale'); +} else if (supportLangs.indexOf(userLang) !== -1) { + lang = supportLangs[supportLangs.indexOf(userLang)]; +} else if (supportLangs.indexOf(userLangCode) !== -1) { + lang = supportLangs[supportLangs.indexOf(userLangCode)]; +} + +locale.val(lang); +locale.change(function() { + Cookies.set('locale', $(this).val(), { + expires: 365 + }); + window.location.reload(); +}); \ No newline at end of file diff --git a/public/views/body.ejs b/public/views/body.ejs index acf929ad..28680e49 100644 --- a/public/views/body.ejs +++ b/public/views/body.ejs @@ -43,15 +43,15 @@ @@ -63,13 +63,13 @@ @@ -81,14 +81,14 @@ @@ -107,7 +107,7 @@ @@ -119,15 +119,15 @@ @@ -139,7 +139,7 @@ -

OR

+

<%= __('OR') %>

@@ -177,7 +177,7 @@ diff --git a/public/views/header.ejs b/public/views/header.ejs index 67760665..d2b1ec1e 100644 --- a/public/views/header.ejs +++ b/public/views/header.ejs @@ -22,18 +22,18 @@