Translations
This commit is contained in:
@@ -14,7 +14,13 @@ class PagesController < ApplicationController
|
||||
def translate
|
||||
key = params[:translationkey]
|
||||
value = params[:translationvalue]
|
||||
if params[:translationhascount] == '1'
|
||||
if params[:auto_translate]
|
||||
if params[:translationlang] == 'en'
|
||||
value = I18n::MissingTranslationExceptionHandler.note(key)
|
||||
else
|
||||
value = I18n.backend.request_translation(key, {}, {fallback: true, locale: params[:translationlang]})
|
||||
end
|
||||
elsif params[:translationhascount] == '1'
|
||||
['zero', 'one', 'two', 'few', 'many'].each { |c|
|
||||
if params['translationpluralization_' + c]
|
||||
if !value.is_a?(Hash)
|
||||
@@ -34,18 +40,46 @@ class PagesController < ApplicationController
|
||||
end
|
||||
store_translations(params[:translationlang], {key => value}, :escape => false)
|
||||
begin
|
||||
render json: {success: true, key: key, jkey: key.gsub('.', '--'), translation: I18n.translate!(key, {:raise => false})}
|
||||
render json: {success: true, key: key, jkey: key.gsub('.', '--'), translation: I18n.translate(key, {:raise => false, :locale => params[:translationlang].to_sym})}
|
||||
rescue
|
||||
render json: {error: 'Failed to load translation'}
|
||||
end
|
||||
end
|
||||
|
||||
def location_territories
|
||||
#render json: (Carmen:::RegionCollection.new(Carmen::Country.coded(params[:country])) || []).to_json
|
||||
territories = {}
|
||||
Carmen::Country.coded(params[:country]).subregions.each { |t| territories[t.code] = t.name }
|
||||
render json: territories.to_json
|
||||
end
|
||||
def location_territories
|
||||
#render json: (Carmen:::RegionCollection.new(Carmen::Country.coded(params[:country])) || []).to_json
|
||||
territories = {}
|
||||
Carmen::Country.coded(params[:country]).subregions.each { |t| territories[t.code] = t.name }
|
||||
render json: territories.to_json
|
||||
end
|
||||
|
||||
def translations
|
||||
@lang = params[:lang]
|
||||
@translations = I18n.backend.get_translation_info
|
||||
I18n.config.enforce_available_locales = false
|
||||
end
|
||||
|
||||
def translation_list
|
||||
total = 0
|
||||
complete = 0
|
||||
@completeness = Hash.new
|
||||
translation_info = I18n.backend.get_translation_info()
|
||||
translation_info.each { |k,v|
|
||||
#total += 1
|
||||
#complete += v['languages'].include?(lang.to_s) ? 1 : 0
|
||||
v['languages'].each { |l|
|
||||
@completeness[l] ||= 0
|
||||
@completeness[l] += 1
|
||||
}
|
||||
}
|
||||
#@test = total ? complete / total : 0
|
||||
@total_translations = translation_info.size()
|
||||
@language_codes = I18n.backend.get_language_codes().select { |s| s }.sort{ | a1, a2 |
|
||||
c2 = @completeness.has_key?(a2.to_s) ? @completeness[a2.to_s] : 0
|
||||
c1 = @completeness.has_key?(a1.to_s) ? @completeness[a1.to_s] : 0
|
||||
c1 == c2 ? a1 <=> a2 : c2 <=> c1
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
def store_translations(locale, data, options = {})
|
||||
|
||||
Reference in New Issue
Block a user