Clean I18n codebase
This commit is contained in:
@@ -4,16 +4,21 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
||||
def index
|
||||
existing_keys = {}
|
||||
@tab = params[:tab] || :debates
|
||||
I18nContent.begins_with_key(@tab).all.
|
||||
map{|content| existing_keys[content.key] = content }
|
||||
|
||||
I18nContent.begins_with_key(@tab)
|
||||
.all
|
||||
.map{ |content| existing_keys[content.key] = content }
|
||||
|
||||
@content = {}
|
||||
|
||||
I18n.backend.send(:translations)[:en].each do |k,v|
|
||||
@content[k.to_s] = flat_hash(v).keys.map{|s| existing_keys["#{k.to_s}.#{s}"].nil? ?
|
||||
@content[k.to_s] = flat_hash(v).keys
|
||||
.map{ |s| existing_keys["#{k.to_s}.#{s}"].nil? ?
|
||||
I18nContent.new(key: "#{k.to_s}.#{s}") :
|
||||
existing_keys["#{k.to_s}.#{s}"] }
|
||||
end
|
||||
@content = @content[@tab.to_s]
|
||||
|
||||
@content = @content[@tab.to_s]
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -25,6 +30,7 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
||||
text.save
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to admin_site_customization_information_texts_path
|
||||
end
|
||||
|
||||
@@ -48,16 +54,16 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
||||
end
|
||||
|
||||
def delete_translations
|
||||
languages_to_delete = params[:delete_translations].select { |k, v| params[:delete_translations][k] == "1" }.keys
|
||||
languages_to_delete = params[:delete_translations].select { |k, v| params[:delete_translations][k] == '1' }.keys
|
||||
languages_to_delete.each do |locale|
|
||||
I18nContentTranslation.destroy_all(locale: locale)
|
||||
end
|
||||
end
|
||||
|
||||
def flat_hash(h, f=nil, g={})
|
||||
def flat_hash(h, f = nil, g = {})
|
||||
return g.update({ f => h }) unless h.is_a? Hash
|
||||
h.each { |k, r| flat_hash(r, [f,k].compact.join('.'), g) }
|
||||
g
|
||||
return g
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
class I18nContent < ActiveRecord::Base
|
||||
|
||||
scope :by_key, -> (key){ where(key: key) }
|
||||
scope :begins_with_key, -> (key){ where("key LIKE ?", "#{key}?%") }
|
||||
scope :begins_with_key, -> (key){ where("key ILIKE ?", "#{key}?%") }
|
||||
|
||||
validates :key, uniqueness: true
|
||||
|
||||
translates :value, touch: true
|
||||
globalize_accessors locales: [:en, :es, :fr, :nl, :val, :pt_br]
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<% group.each do |content| %>
|
||||
<b><%= t(content[:key]) %></b>
|
||||
<% content.globalize_locales.each do |locale| %>
|
||||
<%= render 'form_field', content: content, locale: locale %>
|
||||
<%= render "form_field", content: content, locale: locale %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
<%= hidden_field_tag "contents[content_#{content.key}][id]", content.key %>
|
||||
<%= text_area_tag "contents[content_#{content.key}]values[value_#{locale}]",
|
||||
content.send("value_#{locale}"),
|
||||
{rows: 5,
|
||||
class: "js-globalize-attribute",
|
||||
style: display_translation?(locale),
|
||||
data: { locale: locale }} %>
|
||||
{ rows: 5,
|
||||
class: "js-globalize-attribute",
|
||||
style: display_translation?(locale),
|
||||
data: { locale: locale }
|
||||
} %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<h2><%= t("welcome.welcome.title") %></h2>
|
||||
|
||||
<div class="user-permissions">
|
||||
|
||||
<p><%= t("welcome.welcome.user_permission_info") %></p>
|
||||
1
|
||||
<ul>
|
||||
<li><span class="icon-check"></span> <%= t("welcome.welcome.user_permission_debates") %></li>
|
||||
<li><span class="icon-check"></span> <%= t("welcome.welcome.user_permission_proposal") %></li>
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
require 'action_view/helpers/tag_helper'
|
||||
require 'i18n/exceptions'
|
||||
require 'action_view/helpers/tag_helper'
|
||||
|
||||
module ActionView
|
||||
# = Action View Translation Helpers
|
||||
module Helpers
|
||||
module TranslationHelper
|
||||
include TagHelper
|
||||
@@ -19,7 +18,6 @@ module ActionView
|
||||
end
|
||||
translate(key, options)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user