Improved translations.

This commit is contained in:
Martin Edenhofer 2012-05-18 16:24:00 +02:00
parent 11402f874d
commit 94a2dce104
6 changed files with 245 additions and 24 deletions

View file

@ -147,18 +147,73 @@ class App.i18n extends App.Ajax
# @include App.Ajax # @include App.Ajax
constructor: -> constructor: ->
@set('de') @locale = 'de'
@set( @locale )
window.T = @translate_content window.T = @translate_content
window.Ti = @translate_inline window.Ti = @translate_inline
# $('.translation [contenteditable]')
$('body')
.delegate '.translation', 'focus', (e) =>
$this = $(e.target)
$this.data 'before', $this.html()
# console.log('11111current', $this.html())
return $this
# .delegate '.translation', 'blur keyup paste', (e) =>
.delegate '.translation', 'blur', (e) =>
$this = $(e.target)
source = $this.attr('data-text')
# get new translation
translation_new = $this.html()
translation_new = ('' + translation_new)
.replace(/<.+?>/g, '')
# set new translation
$this.html(translation_new)
# update translation
return if $this.data('before') is translation_new
console.log 'Translation Update', translation_new, $this.data 'before'
$this.data 'before', translation_new
# update runtime translation map
@map[ source ] = translation_new
# replace rest in page
$(".translation[data-text='#{source}']").html( translation_new )
# update permanent translation map
translation = App.Translation.findByAttribute( 'source', source )
if translation
translation.updateAttribute( 'target', translation_new )
else
translation = new App.Translation
translation.load(
locale: @locale,
source: source,
target: translation_new,
)
translation.save()
return $this
set: (locale) => set: (locale) =>
@map = {} @map = {}
@ajax( @ajax(
type: 'GET', type: 'GET',
url: '/' + locale + '.json', url: '/translations/lang/' + locale,
async: false, async: false,
success: (data, status, xhr) => success: (data, status, xhr) =>
@map = data
# load translation collection
for object in data
@map[ object[1] ] = object[2]
# load in collection if needed
App.Translation.refresh( { id: object[0], source: object[1], target: object[2], locale: @locale }, options: { clear: true } )
error: (xhr, statusText, error) => error: (xhr, statusText, error) =>
console.log 'error', error, statusText, xhr.statusCode console.log 'error', error, statusText, xhr.statusCode
) )
@ -231,26 +286,6 @@ class App.Run extends Spine.Controller
window.Session['UISeletion'] = @getSelected() + '' window.Session['UISeletion'] = @getSelected() + ''
) )
# $('.translation [contenteditable]')
$('.translation')
.live 'focus', ->
$this = $(this)
$this.data 'before', $this.html()
console.log('11111before', $this.html())
return $this
.live 'blur keyup paste', ->
# .live 'blur', ->
$this = $(this)
if $this.data('before') isnt $this.html()
$this.data 'before', $this.html()
$this.trigger('change')
console.log('111changed', $this.html(), $this.attr('data-text') )
a = $this.html()
a = ('' + a)
.replace(/<.+?>/g, '')
$this.html(a)
return $this
# @ws = new WebSocket("ws://localhost:3001/"); # @ws = new WebSocket("ws://localhost:3001/");
# Set event handlers. # Set event handlers.

View file

@ -0,0 +1,3 @@
class App.Translation extends App.Model
@configure 'Translation', 'source', 'target', 'locale'
@extend Spine.Model.Ajax

View file

@ -0,0 +1,64 @@
class TranslationsController < ApplicationController
before_filter :authentication_check, :except => [:load]
# GET /translations/:lang
def load
translations = Translation.where( :locale => params[:locale] )
list = []
translations.each { |item|
data = [
item.id,
item.source,
item.target,
]
list.push data
}
render :json => list
end
# GET /translations
def index
@translations = Translation.all
render :json => @translations
end
# GET /translations/1
def show
@translation = Translation.find(params[:id])
render :json => @translation
end
# POST /translations
def create
@translation = Translation.new(params[:translation])
if @translation.save
render :json => @translation, :status => :created
else
render :json => @translation.errors, :status => :unprocessable_entity
end
end
# PUT /translations/1
def update
@translation = Translation.find(params[:id])
if @translation.update_attributes(params[:translation])
render :json => @translation, :status => :ok
else
render :json => @translation.errors, :status => :unprocessable_entity
end
end
# DELETE /translations/1
def destroy
@translation = Translation.find(params[:id])
@translation.destroy
head :ok
end
end

View file

@ -0,0 +1,8 @@
class Translation < ApplicationModel
before_create :set_initial
private
def set_initial
self.target_initial = self.target
end
end

View file

@ -0,0 +1,17 @@
class CreateTranslation < ActiveRecord::Migration
def up
create_table :translations do |t|
t.column :locale, :string, :limit => 10, :null => false
t.column :source, :string, :limit => 255, :null => false
t.column :target, :string, :limit => 255, :null => false
t.column :target_initial, :string, :limit => 255, :null => false
t.timestamps
end
add_index :translations, [:source]
add_index :translations, [:locale]
end
def down
drop_table :translations
end
end

View file

@ -1478,3 +1478,97 @@ Network::Item::Comment.create(
:body => 'Some comment....', :body => 'Some comment....',
:created_by_id => User.where(:login => '-').first.id :created_by_id => User.where(:login => '-').first.id
) )
Translation.create( :locale => 'de', :source => "New", :target => "Neu" )
Translation.create( :locale => 'de', :source => "Create", :target => "Erstellen" )
Translation.create( :locale => 'de', :source => "Cancel", :target => "Abbrechen" )
Translation.create( :locale => 'de', :source => "Submit", :target => "Übermitteln" )
Translation.create( :locale => 'de', :source => "Sign out", :target => "Abmelden" )
Translation.create( :locale => 'de', :source => "Profile", :target => "Profil" )
Translation.create( :locale => 'de', :source => "Settings", :target => "Einstellungen" )
Translation.create( :locale => 'de', :source => "Overviews", :target => "Übersichten" )
Translation.create( :locale => 'de', :source => "Manage", :target => "Verwalten" )
Translation.create( :locale => 'de', :source => "Users", :target => "Benutzer" )
Translation.create( :locale => 'de', :source => "Groups", :target => "Gruppen" )
Translation.create( :locale => 'de', :source => "Group", :target => "Gruppe" )
Translation.create( :locale => 'de', :source => "Organizations", :target => "Organisationen" )
Translation.create( :locale => 'de', :source => "Organization", :target => "Organisation" )
Translation.create( :locale => 'de', :source => "Recent Viewed", :target => "Zuletzt angesehen" )
Translation.create( :locale => 'de', :source => "Security", :target => "Sicherheit" )
Translation.create( :locale => 'de', :source => "From", :target => "Von" )
Translation.create( :locale => 'de', :source => "Title", :target => "Titel" )
Translation.create( :locale => 'de', :source => "Customer", :target => "Kunde" )
Translation.create( :locale => 'de', :source => "State", :target => "Status" )
Translation.create( :locale => 'de', :source => "Created", :target => "Erstellt" )
Translation.create( :locale => 'de', :source => "Attributes", :target => "Attribute" )
Translation.create( :locale => 'de', :source => "Direction", :target => "Richtung" )
Translation.create( :locale => 'de', :source => "Owner", :target => "Besitzer" )
Translation.create( :locale => 'de', :source => "Subject", :target => "Betreff" )
Translation.create( :locale => 'de', :source => "Priority", :target => "Priorität" )
Translation.create( :locale => 'de', :source => "Select the customer of the Ticket or create one.", :target => "Wähle den Kunden eine Tickets oder erstell einen neuen." )
Translation.create( :locale => 'de', :source => "New Ticket", :target => "Neues Ticket" )
Translation.create( :locale => 'de', :source => "Firstname", :target => "Vorname" )
Translation.create( :locale => 'de', :source => "Lastname", :target => "Nachname" )
Translation.create( :locale => 'de', :source => "Phone", :target => "Telefon" )
Translation.create( :locale => 'de', :source => "Street", :target => "Straße" )
Translation.create( :locale => 'de', :source => "Zip", :target => "PLZ" )
Translation.create( :locale => 'de', :source => "City", :target => "Stadt" )
Translation.create( :locale => 'de', :source => "Note", :target => "Notiz" )
Translation.create( :locale => 'de', :source => "note", :target => "Notiz" )
Translation.create( :locale => 'de', :source => "New User", :target => "Neuer Benutzer" )
Translation.create( :locale => 'de', :source => "new", :target => "neu" )
Translation.create( :locale => 'de', :source => "closed", :target => "geschlossen" )
Translation.create( :locale => 'de', :source => "open", :target => "offen" )
Translation.create( :locale => 'de', :source => "pending", :target => "warten" )
Translation.create( :locale => 'de', :source => "Activity Stream", :target => "Aktivitäts-Stream" )
Translation.create( :locale => 'de', :source => "updated", :target => "aktuallisierte" )
Translation.create( :locale => 'de', :source => "My assigned Tickets", :target => "Meine zugewisenen Tickets" )
Translation.create( :locale => 'de', :source => "Unassigned Tickets", :target => "Nicht zugewisene/freie Tickets" )
Translation.create( :locale => 'de', :source => "All Tickets", :target => "Alle Tickets" )
Translation.create( :locale => 'de', :source => "Escalated Tickets", :target => "Eskallierte Tickets" )
Translation.create( :locale => 'de', :source => "My pending reached Tickets", :target => "Meine warten erreicht Tickets" )
Translation.create( :locale => 'de', :source => "Password", :target => "Passwort" )
Translation.create( :locale => 'de', :source => "Password (confirm)", :target => "Passwort (bestätigen)" )
Translation.create( :locale => 'de', :source => "Roles", :target => "Rollen" )
Translation.create( :locale => 'de', :source => "Active", :target => "Aktiv" )
Translation.create( :locale => 'de', :source => "Edit", :target => "Bearbeiten" )
Translation.create( :locale => 'de', :source => "Base", :target => "Basis" )
Translation.create( :locale => 'de', :source => "Number", :target => "Nummer" )
Translation.create( :locale => 'de', :source => "Sender Format", :target => "Absender Format" )
Translation.create( :locale => 'de', :source => "Authentication", :target => "Authorisierung" )
Translation.create( :locale => 'de', :source => "Product Name", :target => "Produkt Name" )
Translation.create( :locale => 'de', :source => "To", :target => "An" )
Translation.create( :locale => 'de', :source => "Customer", :target => "Kunde" )
Translation.create( :locale => 'de', :source => "Linked Accounts", :target => "Verknüpfte Accounts" )
Translation.create( :locale => 'de', :source => "Sign in with", :target => "Anmelden mit" )
Translation.create( :locale => 'de', :source => "Username or email", :target => "Benutzer oder Email" )
Translation.create( :locale => 'de', :source => "Remember me", :target => "An mich erinnern" )
Translation.create( :locale => 'de', :source => "Forgot password?", :target => "Passwort vergessen?" )
Translation.create( :locale => 'de', :source => "Sign in using", :target => "Anmelden über" )
Translation.create( :locale => 'de', :source => "New to", :target => "Neu bei" )
Translation.create( :locale => 'de', :source => "join today!", :target => "werde Teil!" )
Translation.create( :locale => 'de', :source => "Sign up", :target => "Registrieren" )
Translation.create( :locale => 'de', :source => "Sign in", :target => "Anmelden" )
Translation.create( :locale => 'de', :source => "Create my account", :target => "Meinen Account erstellen" )
Translation.create( :locale => 'de', :source => "Login successfully! Have a nice day!", :target => "Anmeldung erfolgreich!" )
Translation.create( :locale => 'de', :source => "Last contact", :target => "Letzter Kontakt" )
Translation.create( :locale => 'de', :source => "Last contact (Agent)", :target => "Letzter Kontakt (Agent)" )
Translation.create( :locale => 'de', :source => "Last contact (Customer)", :target => "Letzter Kontakt (Kunde)" )
Translation.create( :locale => 'de', :source => "Close time", :target => "Schließzeit" )
Translation.create( :locale => 'de', :source => "First response", :target => "Erste Reaktion" )
Translation.create( :locale => 'de', :source => "Ticket %s created!", :target => "Ticket %s erstellt!" )
Translation.create( :locale => 'de', :source => "day", :target => "Tag" )
Translation.create( :locale => 'de', :source => "days", :target => "Tage" )
Translation.create( :locale => 'de', :source => "hour", :target => "Stunde" )
Translation.create( :locale => 'de', :source => "hours", :target => "Stunden" )
Translation.create( :locale => 'de', :source => "minute", :target => "Minute" )
Translation.create( :locale => 'de', :source => "minutes", :target => "Minuten" )
Translation.create( :locale => 'de', :source => "See more", :target => "mehr anzeigen" )
Translation.create( :locale => 'de', :source => "Search", :target => "Suche" )
Translation.create( :locale => 'de', :source => "Forgot your password?", :target => "Passwort vergessen?" )
Translation.create( :locale => 'de', :source => "Templates", :target => "Vorlagen" )
Translation.create( :locale => 'de', :source => "Delete", :target => "Löschen" )
Translation.create( :locale => 'de', :source => "Apply", :target => "Übernehmen" )
Translation.create( :locale => 'de', :source => "Save as Template", :target => "Als Template speichern" )
Translation.create( :locale => 'de', :source => "Save", :target => "Speichern" )
#Translation.create( :locale => 'de', :source => "", :target => "" )