Improved i18n and sync with new translations.
This commit is contained in:
parent
ed891818ed
commit
46557532aa
5 changed files with 99 additions and 73 deletions
|
@ -80,7 +80,10 @@ class TranslationToDo extends App.Controller
|
||||||
|
|
||||||
# local update
|
# local update
|
||||||
App.i18n.removeNotTranslated( @locale, source )
|
App.i18n.removeNotTranslated( @locale, source )
|
||||||
App.i18n.setMap( source, target )
|
|
||||||
|
# update runtime if same language is used
|
||||||
|
if App.i18n.get() is @locale
|
||||||
|
App.i18n.setMap( source, target, 'string' )
|
||||||
|
|
||||||
# remote update
|
# remote update
|
||||||
params =
|
params =
|
||||||
|
@ -109,7 +112,10 @@ class TranslationToDo extends App.Controller
|
||||||
|
|
||||||
# local update
|
# local update
|
||||||
App.i18n.removeNotTranslated( @locale, source )
|
App.i18n.removeNotTranslated( @locale, source )
|
||||||
App.i18n.setMap( source, source )
|
|
||||||
|
# update runtime if same language is used
|
||||||
|
if App.i18n.get() is @locale
|
||||||
|
App.i18n.setMap( source, source, 'string' )
|
||||||
|
|
||||||
# remote update
|
# remote update
|
||||||
params =
|
params =
|
||||||
|
@ -157,10 +163,17 @@ class TranslationList extends App.Controller
|
||||||
#if !App.i18n.notTranslatedFeatureEnabled(@locale)
|
#if !App.i18n.notTranslatedFeatureEnabled(@locale)
|
||||||
# return
|
# return
|
||||||
|
|
||||||
|
@strings = []
|
||||||
|
@times = []
|
||||||
|
for item in data.list
|
||||||
|
if item[4] is 'time'
|
||||||
|
@times.push item
|
||||||
|
else
|
||||||
|
@strings.push item
|
||||||
|
|
||||||
@html App.view('translation/list')(
|
@html App.view('translation/list')(
|
||||||
list: data.list
|
times: @times
|
||||||
timestampFormat: data.timestampFormat
|
strings: @strings
|
||||||
dateFormat: data.dateFormat
|
|
||||||
)
|
)
|
||||||
ui = @
|
ui = @
|
||||||
@$('.js-Item').each( (e) ->
|
@$('.js-Item').each( (e) ->
|
||||||
|
@ -174,11 +187,19 @@ class TranslationList extends App.Controller
|
||||||
id = field.data('id')
|
id = field.data('id')
|
||||||
source = field.data('source')
|
source = field.data('source')
|
||||||
initial = field.data('initial')
|
initial = field.data('initial')
|
||||||
|
format = field.data('format')
|
||||||
|
|
||||||
# if it's translated by user it self, delete it
|
# if it's translated by user it self, delete it
|
||||||
if !initial || initial is ''
|
if !initial || initial is ''
|
||||||
|
|
||||||
|
# locale reset
|
||||||
$(e.target).closest('tr').remove()
|
$(e.target).closest('tr').remove()
|
||||||
App.i18n.setMap( source, '' )
|
|
||||||
|
# update runtime if same language is used
|
||||||
|
if App.i18n.get() is @locale
|
||||||
|
App.i18n.setMap( source, '', format )
|
||||||
|
|
||||||
|
# remote reset
|
||||||
params =
|
params =
|
||||||
id: id
|
id: id
|
||||||
@ajax(
|
@ajax(
|
||||||
|
@ -188,17 +209,21 @@ class TranslationList extends App.Controller
|
||||||
data: JSON.stringify(params)
|
data: JSON.stringify(params)
|
||||||
processData: false
|
processData: false
|
||||||
success: =>
|
success: =>
|
||||||
console.log('aaa', @locale, source)
|
|
||||||
App.i18n.setNotTranslated( @locale, source )
|
App.i18n.setNotTranslated( @locale, source )
|
||||||
App.Event.trigger('i18n:translation_todo_reload')
|
App.Event.trigger('i18n:translation_todo_reload')
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
# update item
|
|
||||||
App.i18n.setMap( source, initial )
|
|
||||||
|
|
||||||
|
# update runtime if same language is used
|
||||||
|
if App.i18n.get() is @locale
|
||||||
|
App.i18n.setMap( source, initial, format )
|
||||||
|
|
||||||
|
# locale reset
|
||||||
field.val( initial )
|
field.val( initial )
|
||||||
@updateRow(id)
|
@updateRow(id)
|
||||||
|
|
||||||
|
# remote reset
|
||||||
params =
|
params =
|
||||||
id: id
|
id: id
|
||||||
target: initial
|
target: initial
|
||||||
|
@ -215,11 +240,15 @@ class TranslationList extends App.Controller
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
id = $( e.target ).data('id')
|
id = $( e.target ).data('id')
|
||||||
source = $( e.target ).data('source')
|
source = $( e.target ).data('source')
|
||||||
|
format = $( e.target ).data('format')
|
||||||
target = $( e.target ).val()
|
target = $( e.target ).val()
|
||||||
@updateRow(id)
|
|
||||||
|
|
||||||
# local update
|
# local update
|
||||||
App.i18n.setMap( source, target )
|
@updateRow(id)
|
||||||
|
|
||||||
|
# update runtime if same language is used
|
||||||
|
if App.i18n.get() is @locale
|
||||||
|
App.i18n.setMap( source, target, format )
|
||||||
|
|
||||||
# remote update
|
# remote update
|
||||||
params =
|
params =
|
||||||
|
|
|
@ -39,10 +39,10 @@ class App.i18n
|
||||||
_instance ?= new _i18nSingleton()
|
_instance ?= new _i18nSingleton()
|
||||||
_instance.set( args )
|
_instance.set( args )
|
||||||
|
|
||||||
@setMap: (source, target) ->
|
@setMap: (source, target, format) ->
|
||||||
if _instance == undefined
|
if _instance == undefined
|
||||||
_instance ?= new _i18nSingleton()
|
_instance ?= new _i18nSingleton()
|
||||||
_instance.setMap( source, target )
|
_instance.setMap( source, target, format )
|
||||||
|
|
||||||
@notTranslatedFeatureEnabled: (locale) ->
|
@notTranslatedFeatureEnabled: (locale) ->
|
||||||
if _instance == undefined
|
if _instance == undefined
|
||||||
|
@ -68,7 +68,8 @@ class _i18nSingleton extends Spine.Module
|
||||||
@include App.LogInclude
|
@include App.LogInclude
|
||||||
|
|
||||||
constructor: ( locale ) ->
|
constructor: ( locale ) ->
|
||||||
@map = {}
|
@mapTime = {}
|
||||||
|
@mapString = {}
|
||||||
@_notTranslatedLog = false
|
@_notTranslatedLog = false
|
||||||
@_notTranslated = {}
|
@_notTranslated = {}
|
||||||
@dateFormat = 'yyyy-mm-dd'
|
@dateFormat = 'yyyy-mm-dd'
|
||||||
|
@ -98,13 +99,13 @@ class _i18nSingleton extends Spine.Module
|
||||||
@log 'debug', 'translate Update', translation_new, $this.data, 'before'
|
@log 'debug', 'translate Update', translation_new, $this.data, 'before'
|
||||||
$this.data 'before', translation_new
|
$this.data 'before', translation_new
|
||||||
|
|
||||||
# update runtime translation map
|
# update runtime translation mapString
|
||||||
@map[ source ] = translation_new
|
@mapString[ source ] = translation_new
|
||||||
|
|
||||||
# replace rest in page
|
# replace rest in page
|
||||||
$(".translation[data-text='#{source}']").html( translation_new )
|
$(".translation[data-text='#{source}']").html( translation_new )
|
||||||
|
|
||||||
# update permanent translation map
|
# update permanent translation mapString
|
||||||
translation = App.Translation.findByAttribute( 'source', source )
|
translation = App.Translation.findByAttribute( 'source', source )
|
||||||
if translation
|
if translation
|
||||||
translation.updateAttribute( 'target', translation_new )
|
translation.updateAttribute( 'target', translation_new )
|
||||||
|
@ -133,7 +134,7 @@ class _i18nSingleton extends Spine.Module
|
||||||
# set lang attribute of html tag
|
# set lang attribute of html tag
|
||||||
$('html').prop( 'lang', locale.substr(0, 2) )
|
$('html').prop( 'lang', locale.substr(0, 2) )
|
||||||
|
|
||||||
@map = {}
|
@mapString = {}
|
||||||
App.Ajax.request(
|
App.Ajax.request(
|
||||||
id: 'i18n-set-' + locale,
|
id: 'i18n-set-' + locale,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
|
@ -141,19 +142,17 @@ class _i18nSingleton extends Spine.Module
|
||||||
async: false,
|
async: false,
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
|
|
||||||
# set timestamp format
|
|
||||||
if data.timestampFormat
|
|
||||||
@timestampFormat = data.timestampFormat
|
|
||||||
|
|
||||||
# set date format
|
|
||||||
if data.dateFormat
|
|
||||||
@dateFormat = data.dateFormat
|
|
||||||
|
|
||||||
# load translation collection
|
# load translation collection
|
||||||
for object in data.list
|
for object in data.list
|
||||||
|
|
||||||
|
# set date/timestamp format
|
||||||
|
if object[3] is 'time'
|
||||||
|
@mapTime[ object[1] ] = object[2]
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
# set runtime lookup table
|
# set runtime lookup table
|
||||||
@map[ object[1] ] = object[2]
|
@mapString[ object[1] ] = object[2]
|
||||||
|
|
||||||
# load in collection if needed
|
# load in collection if needed
|
||||||
App.Translation.refresh( { id: object[0], source: object[1], target: object[2], locale: @locale } )
|
App.Translation.refresh( { id: object[0], source: object[1], target: object[2], locale: @locale } )
|
||||||
|
@ -188,9 +187,9 @@ class _i18nSingleton extends Spine.Module
|
||||||
return '' if string is ''
|
return '' if string is ''
|
||||||
|
|
||||||
# return translation
|
# return translation
|
||||||
if @map[string] isnt undefined
|
if @mapString[string] isnt undefined
|
||||||
@_translated = true
|
@_translated = true
|
||||||
translated = @map[string]
|
translated = @mapString[string]
|
||||||
else
|
else
|
||||||
@_translated = false
|
@_translated = false
|
||||||
translated = string
|
translated = string
|
||||||
|
@ -209,8 +208,11 @@ class _i18nSingleton extends Spine.Module
|
||||||
# return translated string
|
# return translated string
|
||||||
return translated
|
return translated
|
||||||
|
|
||||||
setMap: ( source, target ) =>
|
setMap: ( source, target, format = 'string' ) =>
|
||||||
@map[source] = target
|
if format is 'time'
|
||||||
|
@mapTime[source] = target
|
||||||
|
else
|
||||||
|
@mapString[source] = target
|
||||||
|
|
||||||
notTranslatedFeatureEnabled: (locale) =>
|
notTranslatedFeatureEnabled: (locale) =>
|
||||||
if locale.substr(0,2) is 'en'
|
if locale.substr(0,2) is 'en'
|
||||||
|
@ -227,10 +229,10 @@ class _i18nSingleton extends Spine.Module
|
||||||
@_notTranslated[locale][key] = true
|
@_notTranslated[locale][key] = true
|
||||||
|
|
||||||
date: ( time, offset ) =>
|
date: ( time, offset ) =>
|
||||||
@convert(time, offset, @dateFormat)
|
@convert(time, offset, @mapTime['date'] || @dateFormat)
|
||||||
|
|
||||||
timestamp: ( time, offset ) =>
|
timestamp: ( time, offset ) =>
|
||||||
@convert(time, offset, @timestampFormat)
|
@convert(time, offset, @mapTime['timestamp'] || @timestampFormat)
|
||||||
|
|
||||||
convert: ( time, offset, format ) =>
|
convert: ( time, offset, format ) =>
|
||||||
s = ( num, digits ) ->
|
s = ( num, digits ) ->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<h2><%- @T('Date & Datetime') %></h2>
|
<h2><%- @T('Date & Datetime') %></h2>
|
||||||
<table class="translationOverview table table-striped table-hover">
|
<table class="translationOverview js-translated table table-striped table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="translationOverview-source"><%- @T('Type') %></th>
|
<th class="translationOverview-source"><%- @T('Type') %></th>
|
||||||
|
@ -9,18 +9,16 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
<% if @times: %>
|
||||||
|
<% for time in @times: %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%- @T('Datetime') %></td>
|
<td title="<%= time[1] %>"><%= time[1] %></td>
|
||||||
<td class="translationOverview-itemContainer"><input class="translationOverview-item form-control" value="<%= @timestampFormat %>"></td>
|
<td class="translationOverview-itemContainer"><input class="js-Item translationOverview-item form-control" value="<%= time[2] %>" data-source="<%= time[1] %>" data-initial="<%= time[3] %>" data-id="<%= time[0] %>" data-format="<%= time[4] %>"></td>
|
||||||
<td></td>
|
<td title="<%= time[3] %>"><%= time[3]%></td>
|
||||||
<td></td>
|
<td><a href="#" class="js-Reset"><%- @T('Reset') %></a></td>
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><%- @T('Date') %></td>
|
|
||||||
<td class="translationOverview-itemContainer"><input class="translationOverview-item form-control" value="<%= @dateFormat %>"></td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -35,11 +33,11 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% if @list: %>
|
<% if @strings: %>
|
||||||
<% for item in @list: %>
|
<% for item in @strings: %>
|
||||||
<tr>
|
<tr>
|
||||||
<td title="<%= item[1] %>"><%= item[1] %></td>
|
<td title="<%= item[1] %>"><%= item[1] %></td>
|
||||||
<td class="translationOverview-itemContainer"><input class="js-Item translationOverview-item form-control" value="<%= item[2] %>" data-source="<%= item[1] %>" data-initial="<%= item[3] %>" data-id="<%= item[0] %>"></td>
|
<td class="translationOverview-itemContainer"><input class="js-Item translationOverview-item form-control" value="<%= item[2] %>" data-source="<%= item[1] %>" data-initial="<%= item[3] %>" data-id="<%= item[0] %>" data-format="<%= item[4] %>"></td>
|
||||||
<td title="<%= item[3] %>"><%= item[3]%></td>
|
<td title="<%= item[3] %>"><%= item[3]%></td>
|
||||||
<td><a href="#" class="js-Reset"><%- @T('Reset') %></a></td>
|
<td><a href="#" class="js-Reset"><%- @T('Reset') %></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
class Locale < ApplicationModel
|
class Locale < ApplicationModel
|
||||||
|
|
||||||
def self.load
|
def self.load
|
||||||
url = 'http://localhost:3001/api/v1/locales'
|
url = 'https://i18n.zammad.com/api/v1/locales'
|
||||||
|
|
||||||
result = UserAgent.get(
|
result = UserAgent.get(
|
||||||
url,
|
url,
|
||||||
|
|
|
@ -28,12 +28,20 @@ load translations from online
|
||||||
)
|
)
|
||||||
result.data.each {|translation|
|
result.data.each {|translation|
|
||||||
#puts translation.inspect
|
#puts translation.inspect
|
||||||
exists = Translation.where(:locale => translation['locale'], :source => translation['source']).first
|
|
||||||
if exists
|
# handle case insensitive sql
|
||||||
|
exists = Translation.where(:locale => translation['locale'], :format => translation['format'], :source => translation['source'])
|
||||||
|
translaten = nil
|
||||||
|
exists.each {|item|
|
||||||
|
if item.source == translation['source']
|
||||||
|
translaten = item
|
||||||
|
end
|
||||||
|
}
|
||||||
|
if translaten
|
||||||
|
|
||||||
# verify if update is needed
|
# verify if update is needed
|
||||||
exists.update_attributes(translation.symbolize_keys!)
|
translaten.update_attributes(translation.symbolize_keys!)
|
||||||
exists.save
|
translaten.save
|
||||||
else
|
else
|
||||||
Translation.create(translation.symbolize_keys!)
|
Translation.create(translation.symbolize_keys!)
|
||||||
end
|
end
|
||||||
|
@ -51,6 +59,7 @@ push translations to online
|
||||||
|
|
||||||
def self.push(locale)
|
def self.push(locale)
|
||||||
|
|
||||||
|
# only push changed translations
|
||||||
translations = Translation.where(:locale => locale)
|
translations = Translation.where(:locale => locale)
|
||||||
translations_to_push = []
|
translations_to_push = []
|
||||||
translations.each {|translation|
|
translations.each {|translation|
|
||||||
|
@ -61,7 +70,7 @@ push translations to online
|
||||||
|
|
||||||
return true if translations_to_push.empty?
|
return true if translations_to_push.empty?
|
||||||
#return translations_to_push
|
#return translations_to_push
|
||||||
url = 'http://localhost:3001/api/v1/thanks_for_your_support'
|
url = 'https://i18n.zammad.com/api/v1/thanks_for_your_support'
|
||||||
|
|
||||||
result = UserAgent.post(
|
result = UserAgent.post(
|
||||||
url,
|
url,
|
||||||
|
@ -103,6 +112,7 @@ get list of translations
|
||||||
item.source,
|
item.source,
|
||||||
item.target,
|
item.target,
|
||||||
item.target_initial,
|
item.target_initial,
|
||||||
|
item.format,
|
||||||
]
|
]
|
||||||
list.push data
|
list.push data
|
||||||
else
|
else
|
||||||
|
@ -110,6 +120,7 @@ get list of translations
|
||||||
item.id,
|
item.id,
|
||||||
item.source,
|
item.source,
|
||||||
item.target,
|
item.target,
|
||||||
|
item.format,
|
||||||
]
|
]
|
||||||
list.push data
|
list.push data
|
||||||
end
|
end
|
||||||
|
@ -121,22 +132,8 @@ get list of translations
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
timestamp_map_default = 'yyyy-mm-dd HH:MM'
|
|
||||||
timestamp_map = {
|
|
||||||
:de => 'dd.mm.yyyy HH:MM',
|
|
||||||
}
|
|
||||||
timestamp = timestamp_map[ locale.to_sym ] || timestamp_map_default
|
|
||||||
|
|
||||||
date_map_default = 'yyyy-mm-dd'
|
|
||||||
date_map = {
|
|
||||||
:de => 'dd.mm.yyyy',
|
|
||||||
}
|
|
||||||
date = date_map[ locale.to_sym ] || date_map_default
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
:list => list,
|
:list => list,
|
||||||
:timestampFormat => timestamp,
|
|
||||||
:dateFormat => date,
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue