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