5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-03 00:16:08 +00:00
panel/app/controllers/i18n_controller.rb

40 lines
1 KiB
Ruby
Raw Normal View History

2018-02-09 21:28:27 +00:00
class I18nController < ApplicationController
2018-09-28 15:27:25 +00:00
include Pundit
2018-02-09 21:28:27 +00:00
before_action :authenticate!
def index
2018-09-28 15:27:25 +00:00
authorize :i18n
2018-02-09 21:28:27 +00:00
@site = find_site
redirect_to site_i18n_edit_path(@site)
end
def edit
2018-09-28 15:27:25 +00:00
authorize :i18n
2018-02-09 21:28:27 +00:00
@site = find_site
2018-02-19 20:00:21 +00:00
@lang_from = params.fetch(:from, I18n.locale.to_s)
2018-02-26 20:32:33 +00:00
@lang_to = params.fetch(:to, @lang_from)
2018-02-19 20:00:21 +00:00
@options = I18n.available_locales.map do |lang|
[ t("i18n.#{lang.to_s}"), lang.to_s ]
end
2018-02-09 21:28:27 +00:00
end
def update
2018-09-28 15:27:25 +00:00
authorize :i18n
2018-02-09 21:28:27 +00:00
@site = find_site
2018-02-19 20:00:21 +00:00
@lang_to = params.require(:i18n).require(:lang_to)
2018-02-19 19:33:28 +00:00
# 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
2018-02-19 20:00:21 +00:00
p = request.parameters[:i18n][@lang_to]
i = JekyllI18n.new(site: @site, lang: @lang_to, attributes: p)
2018-02-19 19:33:28 +00:00
if i.save
redirect_to site_path(@site)
else
render 'i18n/edit'
end
2018-02-09 21:28:27 +00:00
end
end