From b41696c15c30a963779874cf8cfa1664c8a7d85f Mon Sep 17 00:00:00 2001 From: f Date: Sat, 23 May 2020 13:52:58 -0300 Subject: [PATCH] WIP traducciones, ya se pueden editar --- app/controllers/posts_controller.rb | 1 + app/models/site.rb | 2 ++ app/views/posts/attributes/_array.haml | 1 + app/views/posts/attributes/_locales.haml | 36 +++++++++++++++++++ .../posts/attributes/_predefined_array.haml | 1 + .../posts/attributes/_related_posts.haml | 1 + app/views/posts/index.haml | 2 +- config/locales/en.yml | 4 +++ config/locales/es.yml | 4 +++ 9 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 app/views/posts/attributes/_locales.haml diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 8d8018a1..76c5cb60 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -16,6 +16,7 @@ class PostsController < ApplicationController @site = find_site @category = params.dig(:category) @layout = params.dig(:layout).try(:to_sym) + @locale = locale # XXX: Cada vez que cambiamos un Post tocamos el sitio con lo que es # más simple saber si hubo cambios. diff --git a/app/models/site.rb b/app/models/site.rb index 3c3e17a2..a1f30c8f 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -235,6 +235,8 @@ class Site < ApplicationRecord # # TODO: Traer recursivamente, si el campo contiene Hash # + # TODO: Mover a PostRelation#pluck + # # @param attr [Symbol|String] El atributo a buscar # @return Array def everything_of(attr, lang: nil) diff --git a/app/views/posts/attributes/_array.haml b/app/views/posts/attributes/_array.haml index 8de3fb9b..04be74a6 100644 --- a/app/views/posts/attributes/_array.haml +++ b/app/views/posts/attributes/_array.haml @@ -4,6 +4,7 @@ .taggable{ data: { values: metadata.value.join(','), name: "post[#{attribute}][]", list: id_for_datalist(attribute), remove: 'false', legend: post_label_t(attribute, post: post), + button: t('posts.attributes.add'), described: id_for_help(attribute) } } = text_field(*field_name_for('post', attribute, '[]'), diff --git a/app/views/posts/attributes/_locales.haml b/app/views/posts/attributes/_locales.haml new file mode 100644 index 00000000..3e1f056b --- /dev/null +++ b/app/views/posts/attributes/_locales.haml @@ -0,0 +1,36 @@ +-# + + Crea un input-map para cada idioma por separado. Podríamos hacer uno + solo que tenga todos los idiomas pero puede ser una interfaz confusa. + + TODO: Esto permite seleccionar más de una traducción por idioma... + +- site.locales.each do |locale| + -# Ignorar el idioma actual + - next if post.lang.value == locale + - values = metadata.value.select do |x| + - metadata.values[locale.to_sym].values.include? x + + .form-group + = label_tag "post_#{attribute}_#{locale}", t(locale) + + .mapable{ data: { values: values.to_json, + 'default-values': metadata.values[locale.to_sym].to_json, + name: "post[#{attribute}][]", + list: id_for_datalist(attribute, locale), + button: t('posts.attributes.add'), + remove: 'false', legend: t(locale), + described: id_for_help(attribute, locale) } } + + = text_field(*field_name_for('post', attribute, '[]'), + value: values.join(', '), + **field_options(attribute, metadata)) + + = render 'posts/attribute_feedback', + post: post, + attribute: [attribute, 'mapable'].flatten, + metadata: metadata + + %datalist{ id: id_for_datalist(attribute, locale) } + - metadata.values[locale.to_sym].keys.each do |value| + %option{ value: value } diff --git a/app/views/posts/attributes/_predefined_array.haml b/app/views/posts/attributes/_predefined_array.haml index 8984cb4e..5926ad75 100644 --- a/app/views/posts/attributes/_predefined_array.haml +++ b/app/views/posts/attributes/_predefined_array.haml @@ -5,6 +5,7 @@ 'default-values': metadata.values.to_json, name: "post[#{attribute}][]", list: id_for_datalist(attribute), remove: 'false', legend: post_label_t(attribute, post: post), + button: t('posts.attributes.add'), described: id_for_help(attribute) } } = text_field(*field_name_for('post', attribute, '[]'), diff --git a/app/views/posts/attributes/_related_posts.haml b/app/views/posts/attributes/_related_posts.haml index 8984cb4e..5926ad75 100644 --- a/app/views/posts/attributes/_related_posts.haml +++ b/app/views/posts/attributes/_related_posts.haml @@ -5,6 +5,7 @@ 'default-values': metadata.values.to_json, name: "post[#{attribute}][]", list: id_for_datalist(attribute), remove: 'false', legend: post_label_t(attribute, post: post), + button: t('posts.attributes.add'), described: id_for_help(attribute) } } = text_field(*field_name_for('post', attribute, '[]'), diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index b43ec190..7177713c 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -39,7 +39,7 @@ .locales - @site.locales.each do |locale| = link_to t(locale), site_posts_path(@site, locale: locale), - class: 'mr-2 mt-2 mb-2' + class: "mr-2 mt-2 mb-2#{locale == @locale ? 'active font-weight-bold' : ''}" %table.table.table-condensed.table-draggable %tbody - @posts.each_with_index do |post, i| diff --git a/config/locales/en.yml b/config/locales/en.yml index 7c0cf805..ae579ada 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -368,6 +368,7 @@ en: invalid_help: 'Some fields need attention! Please search for the fields marked as invalid.' sending_help: Saving, please wait... attributes: + add: Add lang: label: Language date: @@ -381,6 +382,9 @@ en: geo: uri: 'Open in app' osm: 'Open in web map' + locales: + mapable: + help: You can link to the article's translation by looking up its title here and pressing Add reorder: 'Reorder posts' sort: by: 'Sort by' diff --git a/config/locales/es.yml b/config/locales/es.yml index c59fa6f5..b2f1c270 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -376,6 +376,7 @@ es: invalid_help: '¡Te faltan completar algunos campos! Busca los que estén marcados como inválidos' sending_help: Guardando, por favor espera... attributes: + add: Agregar lang: label: Idioma date: @@ -389,6 +390,9 @@ es: geo: uri: 'Abrir en aplicación' osm: 'Abrir en mapa web' + locales: + mapable: + help: Puedes vincular traducciones buscando el título aquí y presionando Agregar reorder: 'Reordenar artículos' sort: by: 'Ordenar por'