Some improvements to admin translation.
This commit is contained in:
parent
24064de220
commit
9b12c6cc7b
9 changed files with 133 additions and 48 deletions
|
@ -228,6 +228,48 @@ class App.ControllerGenericDescription extends App.ControllerModal
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@hide()
|
@hide()
|
||||||
|
|
||||||
|
class App.ControllerModalLoading extends App.Controller
|
||||||
|
className: 'modal fade'
|
||||||
|
|
||||||
|
constructor: ->
|
||||||
|
super
|
||||||
|
|
||||||
|
if @container
|
||||||
|
@el.addClass('modal--local')
|
||||||
|
|
||||||
|
@render()
|
||||||
|
|
||||||
|
@el.modal
|
||||||
|
keyboard: false
|
||||||
|
show: true
|
||||||
|
backdrop: false
|
||||||
|
container: @container
|
||||||
|
|
||||||
|
render: ->
|
||||||
|
@html App.view('generic/modal_loader')(
|
||||||
|
head: @head
|
||||||
|
message: App.i18n.translateContent(@message)
|
||||||
|
)
|
||||||
|
|
||||||
|
update: (message, translate = true) =>
|
||||||
|
if translate
|
||||||
|
message = App.i18n.translateContent(message)
|
||||||
|
@$('.js-loading').html(message)
|
||||||
|
|
||||||
|
hideIcon: =>
|
||||||
|
@$('.js-loadingIcon').addClass('hide')
|
||||||
|
|
||||||
|
showIcon: =>
|
||||||
|
@$('.js-loadingIcon').removeClass('hide')
|
||||||
|
|
||||||
|
hide: (delay) =>
|
||||||
|
remove = =>
|
||||||
|
@el.remove()
|
||||||
|
if !delay
|
||||||
|
remove()
|
||||||
|
return
|
||||||
|
App.Delay.set(remove, delay * 1000)
|
||||||
|
|
||||||
class App.ControllerGenericDestroyConfirm extends App.ControllerModal
|
class App.ControllerGenericDestroyConfirm extends App.ControllerModal
|
||||||
constructor: ->
|
constructor: ->
|
||||||
super
|
super
|
||||||
|
|
|
@ -52,80 +52,83 @@ class Index extends App.ControllerContent
|
||||||
pushChanges: =>
|
pushChanges: =>
|
||||||
locale = @$('[name="locale"]').val()
|
locale = @$('[name="locale"]').val()
|
||||||
|
|
||||||
@modal = new App.ControllerModal(
|
@loader = new App.ControllerModalLoading(
|
||||||
head: 'Pushing own translations...'
|
head: 'Push my changes'
|
||||||
message: 'Pushing own translations to i18n.zammad.com, Thanks for contributing!'
|
message: 'Pushing translations to i18n.zammad.com'
|
||||||
cancel: false
|
|
||||||
close: false
|
|
||||||
shown: true
|
|
||||||
container: @el.closest('.content')
|
container: @el.closest('.content')
|
||||||
)
|
)
|
||||||
|
|
||||||
@ajax(
|
@ajax(
|
||||||
id: 'translations'
|
id: 'translations'
|
||||||
type: 'PUT'
|
type: 'PUT'
|
||||||
url: @apiPath + '/translations/push'
|
url: "#{@apiPath}/translations/push"
|
||||||
data: JSON.stringify(locale: locale)
|
data: JSON.stringify(locale: locale)
|
||||||
processData: false
|
processData: false
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
@modal.hide()
|
@loader.update('Thanks for contributing!')
|
||||||
|
@loader.hideIcon()
|
||||||
|
@loader.hide(2)
|
||||||
error: =>
|
error: =>
|
||||||
@modal.hide()
|
@loader.hide()
|
||||||
)
|
)
|
||||||
|
|
||||||
resetChanges: =>
|
resetChanges: =>
|
||||||
locale = @$('[name="locale"]').val()
|
locale = @$('[name="locale"]').val()
|
||||||
|
|
||||||
@modal = new App.ControllerModal(
|
@loader = new App.ControllerModalLoading(
|
||||||
head: 'Reseting changes...'
|
head: 'Reset changes'
|
||||||
message: 'Reseting changes own translation changes...'
|
message: 'Reseting changes...'
|
||||||
cancel: false
|
|
||||||
close: false
|
|
||||||
shown: true
|
|
||||||
container: @el.closest('.content')
|
container: @el.closest('.content')
|
||||||
)
|
)
|
||||||
|
|
||||||
@ajax(
|
@ajax(
|
||||||
id: 'translations'
|
id: 'translations'
|
||||||
type: 'POST'
|
type: 'POST'
|
||||||
url: @apiPath + '/translations/reset'
|
url: "#{@apiPath}/translations/reset"
|
||||||
data: JSON.stringify(locale: locale)
|
data: JSON.stringify(locale: locale)
|
||||||
processData: false
|
processData: false
|
||||||
success: (data, status, xhr) =>
|
success: (data, status, xhr) =>
|
||||||
App.Event.trigger('i18n:translation_todo_reload')
|
App.Event.trigger('i18n:translation_todo_reload')
|
||||||
App.Event.trigger('i18n:translation_list_reload')
|
App.Event.trigger('i18n:translation_list_reload')
|
||||||
@hideAction()
|
@hideAction()
|
||||||
@modal.hide()
|
@loader.hide()
|
||||||
error: =>
|
error: =>
|
||||||
@modal.hide()
|
@loader.hide()
|
||||||
)
|
)
|
||||||
|
|
||||||
syncChanges: =>
|
syncChanges: =>
|
||||||
locale = @$('[name="locale"]').val()
|
locale = @$('[name="locale"]').val()
|
||||||
|
|
||||||
@modal = new App.ControllerModal(
|
@loader = new App.ControllerModalLoading(
|
||||||
head: 'Syncing with latest translations...'
|
head: 'Get latest translations'
|
||||||
message: 'Syncing with latest translations!'
|
message: 'Getting latest translations from i18n.zammad.com'
|
||||||
cancel: false
|
|
||||||
close: false
|
|
||||||
shown: true
|
|
||||||
container: @el.closest('.content')
|
container: @el.closest('.content')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
hide = =>
|
||||||
|
@hideAction()
|
||||||
|
App.Event.trigger('i18n:translation_todo_reload')
|
||||||
|
App.Event.trigger('i18n:translation_list_reload')
|
||||||
|
@loader.hide(1)
|
||||||
|
|
||||||
|
locales = App.Locale.all()
|
||||||
|
locale = locales.shift()
|
||||||
|
@_syncChanges(locale, locales, @loader, hide)
|
||||||
|
|
||||||
|
_syncChanges: (locale, locales, loader, hide) =>
|
||||||
@ajax(
|
@ajax(
|
||||||
id: 'translations'
|
id: 'translations'
|
||||||
type: 'POST'
|
type: 'GET'
|
||||||
url: @apiPath + '/translations/sync'
|
url: "#{@apiPath}/translations/sync/#{locale.locale}"
|
||||||
data: JSON.stringify(locale: locale)
|
|
||||||
processData: false
|
processData: false
|
||||||
success: (data, status, xhr) =>
|
complete: (data, status, xhr) =>
|
||||||
App.Event.trigger('i18n:translation_todo_reload')
|
loader.update(locale.name, false)
|
||||||
App.Event.trigger('i18n:translation_list_reload')
|
locale = locales.shift()
|
||||||
@hideAction()
|
if _.isEmpty(locales)
|
||||||
@modal.hide()
|
hide()
|
||||||
error: =>
|
return
|
||||||
@modal.hide()
|
@_syncChanges(locale, locales, loader, hide)
|
||||||
)
|
)
|
||||||
|
|
||||||
class TranslationToDo extends App.Controller
|
class TranslationToDo extends App.Controller
|
||||||
hasChanges: false
|
hasChanges: false
|
||||||
|
@ -149,6 +152,7 @@ class TranslationToDo extends App.Controller
|
||||||
return
|
return
|
||||||
|
|
||||||
if !App.i18n.getNotTranslated(@locale)
|
if !App.i18n.getNotTranslated(@locale)
|
||||||
|
@html ''
|
||||||
return
|
return
|
||||||
|
|
||||||
listNotTranslated = []
|
listNotTranslated = []
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<div class="modal-dialog wizard">
|
||||||
|
|
||||||
|
<form class="modal-content setup wizard">
|
||||||
|
<div class="modal-header">
|
||||||
|
<!--<div class="modal-close js-close">
|
||||||
|
<%- @Icon('diagonal-cross') %>
|
||||||
|
</div>-->
|
||||||
|
<h1 class="modal-title"><%- @T(@head) %></h1>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="wizard-body vertical justified">
|
||||||
|
<p class="wizard-loadingText">
|
||||||
|
<span class="loading icon js-loadingIcon"></span> <span class="js-loading"><%- @message %> </span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer"></div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
|
@ -3,9 +3,9 @@
|
||||||
<h1><%- @T('Translations') %> <small></small></h1>
|
<h1><%- @T('Translations') %> <small></small></h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="page-header-meta">
|
<div class="page-header-meta">
|
||||||
<a class="btn btn--success js-syncChanges"><%- @T('Sync with latest') %></a>
|
<a class="btn btn--success js-syncChanges"><%- @T('Get latest translations') %></a>
|
||||||
<a class="btn btn--danger hidden js-changes js-resetChanges"><%- @T('Reset Changes') %></a>
|
<a class="btn btn--danger hidden js-changes js-resetChanges"><%- @T('Reset changes') %></a>
|
||||||
<a class="btn btn--primary hidden js-changes js-pushChanges"><%- @T('Push Changes') %></a>
|
<a class="btn btn--primary hidden js-changes js-pushChanges"><%- @T('Push my changes') %></a>
|
||||||
<div class="language"></div>
|
<div class="language"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,11 +19,10 @@ class TranslationsController < ApplicationController
|
||||||
render json: { message: 'ok' }, status: :ok
|
render json: { message: 'ok' }, status: :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /translations/sync
|
# POST /translations/sync/:locale
|
||||||
def sync
|
def sync
|
||||||
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
return if deny_if_not_role(Z_ROLENAME_ADMIN)
|
||||||
Locale.load
|
Translation.load(params[:locale])
|
||||||
Translation.load
|
|
||||||
render json: { message: 'ok' }, status: :ok
|
render json: { message: 'ok' }, status: :ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,14 @@
|
||||||
|
|
||||||
class Locale < ApplicationModel
|
class Locale < ApplicationModel
|
||||||
|
|
||||||
|
def self.to_sync
|
||||||
|
locales = Locale.where(active: true)
|
||||||
|
if Rails.env.test?
|
||||||
|
locales = Locale.where(active: true, locale: ['en-us', 'de-de'])
|
||||||
|
end
|
||||||
|
locales
|
||||||
|
end
|
||||||
|
|
||||||
def self.load
|
def self.load
|
||||||
url = 'https://i18n.zammad.com/api/v1/locales'
|
url = 'https://i18n.zammad.com/api/v1/locales'
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,28 @@ class Translation < ApplicationModel
|
||||||
|
|
||||||
load translations from online
|
load translations from online
|
||||||
|
|
||||||
|
all:
|
||||||
|
|
||||||
Translation.load
|
Translation.load
|
||||||
|
|
||||||
|
dedicated:
|
||||||
|
|
||||||
|
Translation.load(locale) # e. g. en-us or de-de
|
||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.load
|
def self.load(dedicated_locale = nil)
|
||||||
locales = Locale.where(active: true)
|
locales_list = []
|
||||||
if Rails.env.test?
|
if !dedicated_locale
|
||||||
locales = Locale.where(active: true, locale: ['en-us', 'de-de'])
|
locales = Locale.to_sync
|
||||||
|
locales.each {|locale|
|
||||||
|
locales_list.push locale.locale
|
||||||
|
}
|
||||||
|
else
|
||||||
|
locales_list = [dedicated_locale]
|
||||||
end
|
end
|
||||||
locales.each {|locale|
|
locales_list.each {|locale|
|
||||||
url = "https://i18n.zammad.com/api/v1/translations/#{locale.locale}"
|
url = "https://i18n.zammad.com/api/v1/translations/#{locale}"
|
||||||
if !UserInfo.current_user_id
|
if !UserInfo.current_user_id
|
||||||
UserInfo.current_user_id = 1
|
UserInfo.current_user_id = 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ Zammad::Application.routes.draw do
|
||||||
api_path = Rails.configuration.api_path
|
api_path = Rails.configuration.api_path
|
||||||
|
|
||||||
match api_path + '/translations/push', to: 'translations#push', via: :put
|
match api_path + '/translations/push', to: 'translations#push', via: :put
|
||||||
match api_path + '/translations/sync', to: 'translations#sync', via: :post
|
match api_path + '/translations/sync/:locale', to: 'translations#sync', via: :get
|
||||||
match api_path + '/translations/reset', to: 'translations#reset', via: :post
|
match api_path + '/translations/reset', to: 'translations#reset', via: :post
|
||||||
match api_path + '/translations/lang/:locale', to: 'translations#load', via: :get
|
match api_path + '/translations/lang/:locale', to: 'translations#load', via: :get
|
||||||
match api_path + '/translations/admin/lang/:locale', to: 'translations#admin', via: :get
|
match api_path + '/translations/admin/lang/:locale', to: 'translations#admin', via: :get
|
||||||
|
|
|
@ -202,6 +202,7 @@ class AgentTicketActionsLevel3Test < TestCase
|
||||||
reload(
|
reload(
|
||||||
browser: browser2,
|
browser: browser2,
|
||||||
)
|
)
|
||||||
|
sleep 2
|
||||||
click(
|
click(
|
||||||
css: '.content.active .js-reset',
|
css: '.content.active .js-reset',
|
||||||
browser: browser2,
|
browser: browser2,
|
||||||
|
|
Loading…
Reference in a new issue