Clean I18n codebase

This commit is contained in:
Angel Perez
2018-07-20 15:06:18 -04:00
parent 6d6dc32c38
commit 26965b43ee
6 changed files with 22 additions and 19 deletions

View File

@@ -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,7 +54,7 @@ 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
@@ -57,7 +63,7 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
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

View File

@@ -1,7 +1,7 @@
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

View File

@@ -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 %>

View File

@@ -5,5 +5,6 @@
{ rows: 5,
class: "js-globalize-attribute",
style: display_translation?(locale),
data: { locale: locale }} %>
data: { locale: locale }
} %>
<% end %>

View File

@@ -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>&nbsp;<%= t("welcome.welcome.user_permission_debates") %></li>
<li><span class="icon-check"></span>&nbsp;<%= t("welcome.welcome.user_permission_proposal") %></li>

View File

@@ -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