WIP de traduccion

This commit is contained in:
f 2018-02-09 18:28:27 -03:00
parent 7d271f3bde
commit 09765a1d18
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
10 changed files with 107 additions and 0 deletions

View file

@ -0,0 +1,21 @@
class I18nController < ApplicationController
before_action :authenticate!
def index
@site = find_site
redirect_to site_i18n_edit_path(@site)
end
def edit
@site = find_site
@lang_from = I18n.locale.to_s
@lang_to = @site.config['i18n'].reject { |i| i == @lang_from }.sample
@lang_to = 'es'
end
def update
@site = find_site
binding.pry
end
end

View file

@ -22,6 +22,25 @@ class Site
end
alias :to_s :id
def data
if @jekyll.data.empty?
@jekyll.read
Rails.logger.info 'Leyendo data'
end
@jekyll.data
end
def config
if @jekyll.config.empty?
@jekyll.read
Rails.logger.info 'Leyendo config'
end
@jekyll.config
end
# Los posts de este sitio
def posts
return @posts if @posts

View file

@ -0,0 +1,6 @@
%h1= t('i18n.translating', from: t("i18n.#{@lang_from}"), to: t("i18n.#{@lang_to}"))
= form_tag site_i18n_path(@site), method: :post, class: 'form' do
.form-group
= submit_tag t('i18n.save'), class: 'btn btn-success'
= render 'i18n/recursive', data: @site.data.dig(@lang_from), superkeys: []

View file

@ -0,0 +1,8 @@
- data.each_pair do |key, value|
- keys = [superkeys, key].flatten
- if value.is_a? String
= render 'i18n/text_field', keys: keys, value: value
- elsif value.is_a? Hash
= render 'i18n/recursive', data: value, superkeys: keys
-# elsif value.is_a? Array
= render 'i18n/recursive_array', data: value

View file

@ -0,0 +1,7 @@
- data.each do |value|
- if value.is_a? String
= render 'i18n/text_field', value: value, key: "#{key}[]"
- elsif value.is_a? Hash
= render 'i18n/recursive', data: value
- elsif value.is_a? Array
= render 'i18n/recursive_array', data: value

View file

@ -0,0 +1,15 @@
.form-group
- key = keys.pop
- form_keys = keys.map { |k| "[#{k.to_s}]" }.join('')
- form_help = (keys.size > 0) ? [keys,key].flatten.join('.') : key
- value = @site.data[@lang_to]
- [keys,key].flatten.each do |k|
- value = value[k]
= label_tag "i18n[#{@lang_to}]#{form_keys}", value
- if value.length > 140
= text_area "i18n[#{@lang_to}]#{form_keys}", key, value: value,
class: 'form-control'
- else
= text_field "i18n[#{@lang_to}]#{form_keys}", key, value: value,
class: 'form-control'
%small.text-muted.form-text= form_help

11
app/views/i18n/edit.haml Normal file
View file

@ -0,0 +1,11 @@
.row
.col
= render 'layouts/breadcrumb',
crumbs: [ link_to(t('sites.index'), sites_path),
link_to(@site.name, site_path(@site)),
t('i18n.index'),
t('i18n.edit')]
.row
.col
= render 'i18n/form'

View file

@ -10,6 +10,14 @@ en:
index: 'Sites'
footer:
powered_by: 'is developed by'
i18n:
index: 'Translations'
edit: 'Edit translations'
save: 'Save'
translating: 'Translating into %{to} from %{from}'
es: 'Castillian Spanish'
en: 'English'
ar: 'Arabic'
posts:
index: 'Posts'
edit: 'Edit'

View file

@ -10,6 +10,14 @@ es:
index: 'Sitios'
footer:
powered_by: 'es desarrollada por'
i18n:
index: 'Traducciones'
edit: 'Editar traducciones'
save: 'Guardar'
translating: 'Traduciendo al %{to} desde %{from}'
es: 'castellano'
en: 'inglés'
ar: 'árabe'
posts:
index: 'Artículos'
edit: 'Editar'

View file

@ -6,5 +6,9 @@ Rails.application.routes.draw do
resources :sites do
resources :posts
get 'i18n', to: 'i18n#index'
get 'i18n/edit', to: 'i18n#edit'
post 'i18n', to: 'i18n#update'
end
end