5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-02 07:14:16 +00:00

Merge branch 'locale-fixes' into rails

This commit is contained in:
f 2021-05-10 15:28:26 -03:00
commit e935fb5433
9 changed files with 47 additions and 98 deletions

View file

@ -40,11 +40,21 @@ class ApplicationController < ActionController::Base
site
end
# Devuelve el idioma actual y si no lo encuentra obtiene uno por
# defecto.
#
# Esto se refiere al idioma de la interfaz, no de los artículos.
def current_locale(include_params: true, site: nil)
return params[:locale] if include_params && params[:locale].present?
current_usuarie&.lang || I18n.locale
end
# El idioma es el preferido por le usuarie, pero no necesariamente se
# corresponde con el idioma de los artículos, porque puede querer
# traducirlos.
def set_locale(&action)
I18n.with_locale(current_usuarie&.lang || I18n.default_locale, &action)
I18n.with_locale(current_locale(include_params: false), &action)
end
# Muestra una página 404

View file

@ -14,7 +14,7 @@ class PostsController < ApplicationController
# Las URLs siempre llevan el idioma actual o el de le usuarie
def default_url_options
{ locale: params[:locale] || current_usuarie&.lang || I18n.locale }
{ locale: current_locale }
end
def index
@ -27,7 +27,7 @@ class PostsController < ApplicationController
# XXX: Cada vez que cambiamos un Post tocamos el sitio con lo que es
# más simple saber si hubo cambios.
if @category || @layout || stale?(@site)
if @category || @layout || stale?([current_usuarie, @site])
@posts = @site.posts(lang: locale)
@posts = @posts.where(categories: @category) if @category
@posts = @posts.where(layout: @layout) if @layout
@ -120,7 +120,7 @@ class PostsController < ApplicationController
# TODO: Notificar si se pudo o no
service.destroy
site.touch
redirect_to site_posts_path(site)
redirect_to site_posts_path(site, locale: post.locale.value)
end
# Reordenar los artículos
@ -133,7 +133,7 @@ class PostsController < ApplicationController
service.reorder
site.touch
redirect_to site_posts_path(site)
redirect_to site_posts_path(site, locale: site.default_locale)
end
# Devuelve el idioma solicitado a través de un parámetro, validando
@ -144,7 +144,7 @@ class PostsController < ApplicationController
# solicite a le usuarie crear el nuevo idioma y que esto lo agregue al
# _config.yml del sitio en lugar de mezclar idiomas.
def locale
@locale ||= site&.locales&.find(-> { I18n.locale }) do |l|
@locale ||= site&.locales&.find(-> { site&.default_locale }) do |l|
l.to_s == params[:locale]
end
end

View file

@ -23,7 +23,7 @@ class SitesController < ApplicationController
def show
authorize site
redirect_to site_posts_path(site)
redirect_to site_posts_path(site, locale: site.default_locale)
end
def new
@ -40,7 +40,7 @@ class SitesController < ApplicationController
params: site_params)
if (@site = service.create).persisted?
redirect_to site_posts_path(@site)
redirect_to site_posts_path(@site, locale: @site.default_locale)
else
render 'new'
end
@ -49,7 +49,7 @@ class SitesController < ApplicationController
def edit
authorize site
breadcrumb site.title, site_posts_path(site), match: :exact
breadcrumb site.title, site_posts_path(site, locale: site.default_locale), match: :exact
breadcrumb 'sites.edit', site_path(site)
SiteService.new(site: site).build_deploys
@ -62,7 +62,7 @@ class SitesController < ApplicationController
usuarie: current_usuarie)
if service.update.valid?
redirect_to site_posts_path(site)
redirect_to site_posts_path(site, locale: site.default_locale)
else
render 'edit'
end
@ -74,7 +74,7 @@ class SitesController < ApplicationController
# XXX: Convertir en una máquina de estados?
DeployJob.perform_async site.id if site.enqueue!
redirect_to site_posts_path(site)
redirect_to site_posts_path(site, locale: site.default_locale)
end
def reorder_posts
@ -94,7 +94,7 @@ class SitesController < ApplicationController
flash[:danger] = I18n.t('errors.posts.reorder')
end
redirect_to site_posts_path(site)
redirect_to site_posts_path(site, locale: site.default_locale)
end
def fetch

View file

@ -43,7 +43,7 @@
- metadata = post[attribute]
- type = metadata.type
- cache metadata do
- cache [metadata, I18n.locale] do
= render("posts/attributes/#{type}",
base: 'post', post: post, attribute: attribute,
metadata: metadata, site: site,

View file

@ -73,10 +73,7 @@
-#
TODO: Solo les usuaries cachean porque tenemos que separar
les botones por permisos.
TODO: Verificar qué pasa cuando se gestiona el sitio en
distintos idiomas a la vez
- cache_if @usuarie, post do
- cache_if @usuarie, [post, I18n.locale] do
- checkbox_id = "checkbox-#{post.uuid.value}"
%tr{ id: post.uuid.value, data: { target: 'reorder.row' } }
%td

View file

@ -22,7 +22,7 @@
- metadata = @post[attr]
- next unless metadata.front_matter?
- cache metadata do
- cache [metadata, I18n.locale] do
= render("posts/attribute_ro/#{metadata.type}",
post: @post, attribute: attr,
metadata: metadata,
@ -36,6 +36,6 @@
- metadata = @post[attr]
- next if metadata.front_matter?
- cache metadata do
- cache [metadata, I18n.locale] do
%section.editor{ id: attr, dir: dir }
= @post.public_send(attr).to_s.html_safe

View file

@ -18,12 +18,12 @@
-#
TODO: Solo les usuaries cachean porque tenemos que separar
les botones por permisos.
- cache_if (rol.usuarie? && !rol.temporal), site do
- cache_if (rol.usuarie? && !rol.temporal), [site, I18n.locale] do
%tr
%td
%h2
- if policy(site).show?
= link_to site.title, site_path(site)
= link_to site.title, site_posts_path(site, locale: site.default_locale)
- else
= site.title
%p.lead= site.description

View file

@ -84,10 +84,6 @@ en:
title: Link to www
success: Success!
error: Error
deploy_private:
title: Private version
success: Success!
error: Error
deploy_zip:
title: Build ZIP file
success: Available for download
@ -96,6 +92,10 @@ en:
title: Host as Tor Hidden Service
success: Success!
error: Error
deploy_private:
title: Private version
success: Success!
error: Error
deploy_alternative_domain:
title: Alternative domain name
success: Success!
@ -123,6 +123,7 @@ en:
models:
usuarie: User
licencia: License
design: Design
attributes:
usuarie:
email: 'E-mail address'
@ -130,27 +131,22 @@ en:
password_confirmation: 'Password confirmation'
current_password: 'Current password'
lang: 'Main language'
remember_me: Remember me
site:
name: 'Name'
title: 'Title'
description: 'Description'
colaboracion_anonima: Enable anonymous collaboration
acepta_invitades: Enable collaboration
colaboracion_anonima: Enable anonymous collaboration
contact: Enable contact forms
tienda_url: Store URL
tienda_api_key: Store access key
errors:
models:
site:
attributes:
deploys:
deploy_local_presence: 'We need to be build the site!'
invitadx:
attributes:
email:
taken: 'This e-mail address is already taken, please choose a different one'
password_confirmation:
confirmation: "The passwords don't match"
acepta_politicas_de_privacidad:
no_acepta_politicas_de_privacidad: "Please read and accept the privacy policy"
design_id:
layout_incompatible:
error: "Design can't be changed because there are posts with incompatible layouts"
@ -182,30 +178,6 @@ en:
usuarie:
edit: Edit my profile
category: 'Category'
i18n:
top: 'Back to top'
index: "Here is where you edit the text on your site that doesn't belong to a post, such as its description, sections, buttons... If you change languages up there in the title to be the same, you can edit them. If they're different, you can translate from one into the other."
count: 'This is the amount of texts.'
toc: 'Jump to this section'
meta: 'Metadata'
navegacion: 'Navigation'
inicio: 'Home'
volver: 'Back'
entrar: 'Enter'
cerrar: 'Close'
anchor: 'Internal links'
nav: 'Menu'
nav-lang: 'Language menu'
modulos: 'Modules'
header: 'Header'
sobre: 'About'
metodologia: 'Methodology'
planeando_recursos: 'Planning resources'
rutas: 'Agendas'
complementarios: 'Materials'
recursos: 'Resources'
contacta: 'Contact us'
agradecimientos: 'Acknowledgments'
sites:
index: 'This is the list of sites you can edit.'
enqueued: "The site is on queue to be generated. Once this
@ -217,6 +189,7 @@ en:
invitations:
accept: "Someone invited you to collaborate on their site. If you accept the invitation, you can access the site's edit mode."
reject: "If you decline, you won't have access."
pull: 'You have pending upgrades!'
close: 'Close help'
deploys:
deploy_local:
@ -321,15 +294,19 @@ en:
new:
title: 'Create site'
submit: 'Create site'
help: 'You can edit any of these options after site creation.'
edit:
title: 'Edit %{site}'
submit: 'Save changes'
btn: 'Configuration'
form:
errors:
title: There were errors and we couldn't save your changes :(
help: Please, look for the invalid fields to fix them
help:
name: "The name of your site. It can only include numbers and letters."
title: 'The title can be anything you want'
description: 'You site description that appears in search engines. Between 50 and 160 characters.'
design: 'Select the design for your site. You can change it later. We add more designs from time to time!'
licencia: 'Everything we publish has automatic copyright. This
means nobody can use our works without explicit permission. By
@ -399,6 +376,7 @@ en:
en: 'English'
ar: 'Arabic'
posts:
caption: Post list
attribute_ro:
file:
download: Download file
@ -480,6 +458,10 @@ en:
blank: Nothing
destroy: Delete
confirm_destroy: Are you sure?
form:
errors:
title: There are some errors on the form
help: Please, verify that all values are correct.
usuaries:
invite_as:
usuaries: users

View file

@ -178,45 +178,8 @@ es:
usuarie:
edit: Editar mi perfil
category: 'Categoría'
i18n:
top: 'Volver al principio'
index: 'Aquí puedes editar todos los textos del sitio que no se
corresponden con artículos, como la descripción, secciones, textos
de botones... Si cambias los idiomas arriba para que coincidan,
puedes editar los textos en el mismo idioma. Si los idiomas no
coinciden, puedes traducirlos de uno a otro.'
count: 'Esta es la cantidad de textos.'
toc: 'Saltar hasta esta sección'
meta: 'Metadata'
navegacion: 'Navegación'
inicio: 'Inicio'
volver: 'Volver'
entrar: 'Entrar'
cerrar: 'Cerrar'
anchor: 'Links internos'
nav: 'Menú'
nav-lang: 'Menú de idiomas'
modulos: 'Módulos'
header: 'Portada'
sobre: 'Acerca'
metodologia: 'Metodología'
planeando_recursos: 'Planeando recursos'
rutas: 'Rutas'
complementarios: 'Materiales complementarios'
recursos: 'Recursos'
contacta: 'Contacta'
agradecimientos: 'Agradecimientos'
sesion: 'Sesiones'
sesiones: 'Sesiones'
anexo: 'Anexo'
simple: 'Simple'
sites:
index: 'Este es el listado de sitios que puedes editar.'
edit_translations: 'Puedes editar los textos que salen en tu sitio
que no corresponden a artículos aquí, además de traducirlos a
otros idiomas.'
edit_posts: 'Aquí verás el listado de todos los artículos y podrás
editarlos o crear nuevos'
enqueued: 'El sitio está en la cola de espera para ser generado.
Una vez que este proceso termine, recibirás un correo indicando el
estado y si todo fue bien, se publicarán los cambios en tu sitio
@ -224,9 +187,6 @@ es:
enqueue: 'Cuando termines de hacer cambios en tu sitio, puedes
publicarlos con esta acción. Al finalizar recibirás un correo
avisándote cómo fue todo.'
build_log: 'Este es el registro de lo que sucedió mientras se
generaba el sitio. Si hubo algún problema, saldrá aquí.'
invitade: 'Les invitades a un sitio solo pueden crear y modificar entradas propias y no pueden publicar sin la revisión de une usuarie'
invitations:
accept: 'Alguien te invitó a colaborar en su sitio. Si aceptas la invitación, tendrás acceso a este sitio.'
reject: 'Si rechazas la invitación, no tendrás acceso.'