diff --git a/app/assets/javascripts/app/controllers/_application_controller.js.coffee b/app/assets/javascripts/app/controllers/_application_controller.js.coffee index 3c1ebfcb4..89bddf8d8 100644 --- a/app/assets/javascripts/app/controllers/_application_controller.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller.js.coffee @@ -399,6 +399,10 @@ class App.Controller extends Spine.Controller if row.callback object[row.name]['name'] = row.callback(object[row.name]['name']) + # check if translation is needed + if row.translate + object[row.name]['name'] = T( object[row.name]['name'] ) + # @log 'table', 'header', header, 'overview', data_types, 'objects', objects table = App.view('generic/table')( header: header, @@ -430,8 +434,8 @@ class App.Controller extends Spine.Controller { name: 'number', link: true }, { name: 'title', link: true }, { name: 'customer', class: 'user-data', data: { id: true } }, - { name: 'ticket_state' }, - { name: 'ticket_priority' }, + { name: 'ticket_state', translate: true }, + { name: 'ticket_priority', translate: true }, { name: 'group' }, { name: 'owner', class: 'user-data', data: { id: true } }, { name: 'created_at', callback: @humanTime }, @@ -488,21 +492,21 @@ class App.Controller extends Spine.Controller if diff >= 86400 unit = Math.round( (diff / 86400) ) if unit > 1 - return unit + ' days' + return unit + ' ' + T('days') else - return unit + ' day' + return unit + ' ' + T('day') if diff >= 3600 unit = Math.round( (diff / 3600) ) if unit > 1 - return unit + ' hours' + return unit + ' ' + T('hours') else - return unit + ' hour' + return unit + ' ' + T('hour') if diff <= 3600 unit = Math.round( (diff / 60) ) if unit > 1 - return unit + ' minutes' + return unit + ' ' + T('minutes') else - return unit + ' minute' + return unit + ' ' + T('minute') userInfo: (data) => # start customer info controller diff --git a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee index afbfe6299..a884c1072 100644 --- a/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee +++ b/app/assets/javascripts/app/controllers/agent_ticket_create.js.coffee @@ -149,7 +149,8 @@ class Index extends App.Controller # notify UI @notify type: 'success', - msg: "Ticket #{r.number} created!", + msg: T('Ticket %s created!', r.number), + link: "#ticket/zoom/#{r.id}" timeout: 12000, # create new create screen diff --git a/app/assets/javascripts/app/controllers/notify.js.coffee b/app/assets/javascripts/app/controllers/notify.js.coffee index 172b10be0..4566eca15 100644 --- a/app/assets/javascripts/app/controllers/notify.js.coffee +++ b/app/assets/javascripts/app/controllers/notify.js.coffee @@ -27,6 +27,8 @@ class App.Notify extends Spine.Controller data['type'] = 'alert' $.noty.closeAll() + if data.link + data.msg = '' + data.msg + '' $('#notify').noty( { text: data.msg, diff --git a/app/assets/javascripts/app/index.js.coffee b/app/assets/javascripts/app/index.js.coffee index 09a9d8df3..1ed374528 100644 --- a/app/assets/javascripts/app/index.js.coffee +++ b/app/assets/javascripts/app/index.js.coffee @@ -141,12 +141,49 @@ class App.Auth extends App.Ajax url: '/signout', ) +class App.i18n extends App.Ajax +# @include App.Ajax + + constructor: -> + @set('de') + window.T = @translate + + set: (locale) => + @map = {} + @ajax( + type: 'GET', + url: '/' + locale + '.json', + async: false, + success: (data, status, xhr) => + @map = data + error: (xhr, statusText, error) => + console.log 'error', error, statusText, xhr.statusCode + ) + + translate: (string, args...) => + + # return translation + if @map[string] isnt undefined + translated = @map[string] + else + translated = string + + # search %s + for arg in args + translated = translated.replace(/%s/, arg) + + # return translated string + return translated + class App.Run extends Spine.Controller constructor: -> super @log 'RUN app'#, @ @el = $('#app') + # init of i18n + new App.i18n + # start navigation controller new App.Navigation( el: @el.find('#navigation') ); diff --git a/app/assets/javascripts/app/views/agent_ticket_view.jst.eco b/app/assets/javascripts/app/views/agent_ticket_view.jst.eco index ee225c0c3..c51d8e106 100644 --- a/app/assets/javascripts/app/views/agent_ticket_view.jst.eco +++ b/app/assets/javascripts/app/views/agent_ticket_view.jst.eco @@ -1,7 +1,7 @@