Moved db access to model.
This commit is contained in:
parent
79bd92c71d
commit
0bf90f17b6
2 changed files with 25 additions and 23 deletions
|
@ -5,28 +5,7 @@ class TranslationsController < ApplicationController
|
||||||
|
|
||||||
# GET /translations/:lang
|
# GET /translations/:lang
|
||||||
def load
|
def load
|
||||||
translations = Translation.where( :locale => params[:locale] )
|
render :json => Translation.list( params[:locale] )
|
||||||
|
|
||||||
list = []
|
|
||||||
translations.each { |item|
|
|
||||||
data = [
|
|
||||||
item.id,
|
|
||||||
item.source,
|
|
||||||
item.target,
|
|
||||||
]
|
|
||||||
list.push data
|
|
||||||
}
|
|
||||||
|
|
||||||
timestamp_map_default = 'yyyy-mm-dd HH:MM'
|
|
||||||
timestamp_map = {
|
|
||||||
:de => 'dd.mm.yyyy HH:MM',
|
|
||||||
}
|
|
||||||
timestamp = timestamp_map[ params[:locale].to_sym ] || timestamp_map_default
|
|
||||||
|
|
||||||
render :json => {
|
|
||||||
:list => list,
|
|
||||||
:timestampFormat => timestamp,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /translations
|
# GET /translations
|
||||||
|
|
|
@ -3,6 +3,29 @@
|
||||||
class Translation < ApplicationModel
|
class Translation < ApplicationModel
|
||||||
before_create :set_initial
|
before_create :set_initial
|
||||||
|
|
||||||
|
def self.list(locale)
|
||||||
|
translations = Translation.where( :locale => locale )
|
||||||
|
list = []
|
||||||
|
translations.each { |item|
|
||||||
|
data = [
|
||||||
|
item.id,
|
||||||
|
item.source,
|
||||||
|
item.target,
|
||||||
|
]
|
||||||
|
list.push data
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
return {
|
||||||
|
:list => list,
|
||||||
|
:timestampFormat => timestamp,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def self.translate(locale, string)
|
def self.translate(locale, string)
|
||||||
|
|
||||||
# translate string
|
# translate string
|
||||||
|
|
Loading…
Reference in a new issue