添加前端国际化文件缓存支持

This commit is contained in:
Yudong
2014-09-25 18:20:34 +08:00
parent fcb3c112e0
commit e48ddb2dd5
4 changed files with 13 additions and 4 deletions

View File

@@ -56,6 +56,7 @@ exports.run = ->
ticket_create_email: fs.readFileSync('./core/template/ticket_create_email.html').toString()
ticket_reply_email: fs.readFileSync('./core/template/ticket_reply_email.html').toString()
app.localeVersion = config.i18n.version
app.use connect.json()
app.use connect.urlencoded()
app.use connect.cookieParser()
@@ -102,7 +103,6 @@ exports.run = ->
app.listen config.web.listen, ->
fs.chmodSync config.web.listen, 0o770
console.log "RootPanel start at #{config.web.listen}"
unless module.parent

View File

@@ -48,5 +48,13 @@ $ ->
window.tErr = (name) ->
return "error_code.#{name}"
$.getJSON "/locale/#{$.cookie('language')}", (data) ->
window.i18n_data = data
clientVersion = localStorage.getItem 'localeVersion'
currentVersion = "#{($ 'body').data 'locale'}"
if clientVersion == currentVersion
window.i18n_data = JSON.parse(localStorage.getItem 'localeContent')
else
$.getJSON "/locale/#{$.cookie('language')}", (data) ->
window.i18n_data = data
localStorage.setItem 'localeVersion', currentVersion
localStorage.setItem 'localeContent', JSON.stringify data

View File

@@ -8,7 +8,7 @@ html
for hook in selectHook('view.layout.styles')
link(rel='stylesheet', href=hook.path)
body
body(data-locale=app.localeVersion)
header.navbar-fixed-top
.container
nav.navbar.navbar-default.navbar-inverse(role='navigation')

View File

@@ -9,6 +9,7 @@ module.exports =
cookie_time: 30 * 24 * 3600 * 1000
i18n:
version: '0,1'
available_language: ['zh_CN']
default_language: 'zh_CN'
default_timezone: 'Asia/Shanghai'