5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 17:26:21 +00:00
panel/app/controllers/i18n_controller.rb

46 lines
1.2 KiB
Ruby
Raw Normal View History

2019-03-26 15:32:20 +00:00
# frozen_string_literal: true
2019-07-03 23:25:23 +00:00
# Controlador de traducciones
2018-02-09 21:28:27 +00:00
class I18nController < ApplicationController
2018-09-28 15:27:25 +00:00
include Pundit
2019-07-03 23:25:23 +00:00
before_action :authenticate_usuarie!
2018-02-09 21:28:27 +00:00
def index
@site = find_site
2019-07-04 00:51:44 +00:00
authorize SiteTranslation.new(@site)
2018-02-09 21:28:27 +00:00
redirect_to site_i18n_edit_path(@site)
end
def edit
@site = find_site
2019-07-04 00:51:44 +00:00
authorize SiteTranslation.new(@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|
2019-03-26 15:32:20 +00:00
[t("i18n.#{lang}"), lang.to_s]
2018-02-19 20:00:21 +00:00
end
2018-02-09 21:28:27 +00:00
end
def update
@site = find_site
2019-07-04 00:51:44 +00:00
authorize SiteTranslation.new(@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
2019-07-04 00:51:44 +00:00
i = JekyllI18n.new(site: @site,
lang: @lang_to,
attributes: request.parameters[:i18n][@lang_to])
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