5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-14 22:51:41 +00:00

intercambiar idiomas

This commit is contained in:
f 2018-02-19 17:00:21 -03:00
parent 4ff314046a
commit 763320cd5e
No known key found for this signature in database
GPG key ID: F3FDAB97B5F9F7E7
6 changed files with 33 additions and 9 deletions

View file

@ -9,19 +9,22 @@ class I18nController < ApplicationController
def edit
@site = find_site
@lang_from = I18n.locale.to_s
@lang_to = @site.config['i18n'].reject { |i| i == @lang_from }.sample
@lang_to = 'ar'
@lang_from = params.fetch(:from, I18n.locale.to_s)
@lang_to = params.fetch(:to, I18n.available_locales.sample.to_s)
@options = I18n.available_locales.map do |lang|
[ t("i18n.#{lang.to_s}"), lang.to_s ]
end
end
def update
@site = find_site
@lang_to = params.require(:i18n).require(:lang_to)
# No usamos params porque nos obliga a hacer una lista blanca de
# todos los parámetros que queremos, pero no tenemos forma aun de
# pasarse a permit un array de todas las keys y sus tipos en base al
# idioma que ya existe
p = request.parameters[:i18n][:ar]
i = JekyllI18n.new(site: @site, lang: :ar, attributes: p)
p = request.parameters[:i18n][@lang_to]
i = JekyllI18n.new(site: @site, lang: @lang_to, attributes: p)
if i.save
redirect_to site_path(@site)

View file

@ -1,5 +1,17 @@
%h1= t('i18n.translating', from: t("i18n.#{@lang_from}"), to: t("i18n.#{@lang_to}"))
= form_tag site_i18n_edit_path(@site), method: :get, class: 'form-inline' do
%h1
= t('i18n.translating.from')
= select_tag 'from',
options_for_select(@options, @lang_from),
class: 'form-control'
= t('i18n.translating.to')
= select_tag 'to',
options_for_select(@options, @lang_to),
class: 'form-control'
= submit_tag t('i18n.change'), class: 'btn btn-info', name: nil
= form_tag site_i18n_path(@site), method: :post, class: 'form' do
= hidden_field 'i18n', 'lang_to', value: @lang_to
.form-group
= submit_tag t('i18n.save'), class: 'btn btn-success'

View file

@ -22,7 +22,9 @@
-# no especificar el id en una key numerica para que no se genere un
-# hash en lugar de un array de valores
- key = '' if key.is_a? Integer
= label_tag "i18n[#{@lang_to}]#{form_keys}[#{key}]", value
- value_to = value if value_to.blank?
= label_tag "i18n[#{@lang_to}]#{form_keys}[#{key}]", value,
class: (@lang_from == 'ar') ? 'rtl' : 'ltr'
-# creamos un campo a mano porque los helpers de niveles mas altos
-# quieren hacer magia con los ids y fallan
- if value.length > 140

View file

@ -11,3 +11,4 @@
- @sites.each do |site|
%tr
%td= link_to site.name, site_path(site)
%td= link_to t('i18n.edit'), site_i18n_edit_path(site)

View file

@ -15,7 +15,10 @@ en:
index: 'Translations'
edit: 'Edit translations'
save: 'Save'
translating: 'Translating into %{to} from %{from}'
change: 'Change'
translating:
from: 'Translating from'
to: 'into'
es: 'Castillian Spanish'
en: 'English'
ar: 'Arabic'

View file

@ -15,7 +15,10 @@ es:
index: 'Traducciones'
edit: 'Editar traducciones'
save: 'Guardar'
translating: 'Traduciendo al %{to} desde %{from}'
change: 'Cambiar'
translating:
from: 'Traduciendo desde'
to: 'a'
es: 'castellano'
en: 'inglés'
ar: 'árabe'