Improved i18n.
This commit is contained in:
parent
422ae18a2d
commit
6b9af49fa8
2 changed files with 39 additions and 6 deletions
|
@ -8,9 +8,11 @@ class App.i18n
|
||||||
|
|
||||||
constructor: ->
|
constructor: ->
|
||||||
@locale = 'de'
|
@locale = 'de'
|
||||||
|
@timestampFormat = 'yyyy-mm-dd HH:MM'
|
||||||
@set( @locale )
|
@set( @locale )
|
||||||
window.T = @translate_content
|
window.T = @translate_content
|
||||||
window.Ti = @translate_inline
|
window.Ti = @translate_inline
|
||||||
|
window.Ts = @timestamp
|
||||||
|
|
||||||
# $('.translation [contenteditable]')
|
# $('.translation [contenteditable]')
|
||||||
$('body')
|
$('body')
|
||||||
|
@ -44,7 +46,7 @@ class App.i18n
|
||||||
$(".translation[data-text='#{source}']").html( translation_new )
|
$(".translation[data-text='#{source}']").html( translation_new )
|
||||||
|
|
||||||
# update permanent translation map
|
# update permanent translation map
|
||||||
translation = App.Translation.findByAttribute( 'source', source )
|
translation = App.Collection.findByAttribute( 'Translation', 'source', source )
|
||||||
if translation
|
if translation
|
||||||
translation.updateAttribute( 'target', translation_new )
|
translation.updateAttribute( 'target', translation_new )
|
||||||
else
|
else
|
||||||
|
@ -58,7 +60,7 @@ class App.i18n
|
||||||
|
|
||||||
return $this
|
return $this
|
||||||
|
|
||||||
set: (locale) =>
|
set: (locale) ->
|
||||||
@map = {}
|
@map = {}
|
||||||
App.Com.ajax(
|
App.Com.ajax(
|
||||||
id: 'i18n-set-' + locale,
|
id: 'i18n-set-' + locale,
|
||||||
|
@ -67,8 +69,12 @@ class App.i18n
|
||||||
async: false,
|
async: false,
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
|
|
||||||
|
# set timestamp format
|
||||||
|
if data.timestampFormat
|
||||||
|
@timestampFormat = data.timestampFormat
|
||||||
|
|
||||||
# load translation collection
|
# load translation collection
|
||||||
for object in data
|
for object in data.list
|
||||||
|
|
||||||
# set runtime lookup table
|
# set runtime lookup table
|
||||||
@map[ object[1] ] = object[2]
|
@map[ object[1] ] = object[2]
|
||||||
|
@ -123,3 +129,27 @@ class App.i18n
|
||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
.replace(/\x22/g, '"')
|
.replace(/\x22/g, '"')
|
||||||
|
|
||||||
|
timestamp: (time) =>
|
||||||
|
s = (num, digits) ->
|
||||||
|
while num.toString().length < digits
|
||||||
|
num = "0" + num
|
||||||
|
return num
|
||||||
|
|
||||||
|
timeObject = new Date(time)
|
||||||
|
d = timeObject.getDate()
|
||||||
|
m = timeObject.getMonth() + 1
|
||||||
|
y = timeObject.getFullYear()
|
||||||
|
S = timeObject.getSeconds()
|
||||||
|
M = timeObject.getMinutes()
|
||||||
|
H = timeObject.getHours()
|
||||||
|
format = @timestampFormat
|
||||||
|
format = format.replace /dd/, s( d, 2 )
|
||||||
|
format = format.replace /d/, d
|
||||||
|
format = format.replace /mm/, s( m, 2 )
|
||||||
|
format = format.replace /m/, m
|
||||||
|
format = format.replace /yyyy/, y
|
||||||
|
format = format.replace /SS/, s( S, 2 )
|
||||||
|
format = format.replace /MM/, s( M, 2 )
|
||||||
|
format = format.replace /HH/, s( H, 2 )
|
||||||
|
return format
|
||||||
|
|
|
@ -15,7 +15,10 @@ class TranslationsController < ApplicationController
|
||||||
list.push data
|
list.push data
|
||||||
}
|
}
|
||||||
|
|
||||||
render :json => list
|
render :json => {
|
||||||
|
:list => list,
|
||||||
|
:timestampFormat => 'dd.mm.yyyy HH:MM',
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /translations
|
# GET /translations
|
||||||
|
|
Loading…
Reference in a new issue