Remove FragmentLocalization and localized_cache helper

We replace the `localized_cache` helper with just simple keys provided
to the `cache` helper, with `locale=#{I18n.locale}` inlined. End of an
era!
This commit is contained in:
Emi Matchu 2024-09-20 20:10:04 -07:00
parent d27c03606f
commit c0e4291745
5 changed files with 5 additions and 27 deletions

View file

@ -2,12 +2,10 @@ require 'async'
require 'async/container'
class ApplicationController < ActionController::Base
include FragmentLocalization
protect_from_forgery
helper_method :current_user, :user_signed_in?
before_action :set_locale
before_action :configure_permitted_parameters, if: :devise_controller?
@ -45,7 +43,7 @@ class ApplicationController < ActionController::Base
def user_signed_in?
auth_user_signed_in?
end
def infer_locale
return params[:locale] if valid_locale?(params[:locale])
return cookies[:locale] if valid_locale?(cookies[:locale])
@ -53,7 +51,7 @@ class ApplicationController < ActionController::Base
http_accept_language.language_region_compatible_from(I18n.available_locales.map(&:to_s)) ||
I18n.default_locale
end
def not_found(record_name='record')
raise ActionController::RoutingError.new("#{record_name} not found")
end

View file

@ -1,6 +1,4 @@
module ApplicationHelper
include FragmentLocalization
def absolute_url(path_or_url)
if path_or_url.include?('://') # already an absolute URL
path_or_url
@ -165,13 +163,6 @@ module ApplicationHelper
options
end
def localized_cache(key={}, &block)
localized_key = localize_fragment_key(key, locale)
# TODO: The digest feature is handy, but it's not compatible with how we
# check for fragments existence in the controller, so skip it for now.
cache(localized_key, skip_digest: true, &block)
end
def auth_user_sign_in_path_with_return_to
new_auth_user_session_path :return_to => request.fullpath

View file

@ -31,7 +31,7 @@
%h2= t '.newest_items.header'
= render @newest_items
- localized_cache :action_suffix => 'species_search_links' do
- cache "items/index species_search_links locale=#{I18n.locale}" do
#species-search-links
%h2= t '.species_search.header'
= standard_species_search_links

View file

@ -90,7 +90,7 @@
%h3= t '.newest_items.unmodeled.header'
%ul#newest-unmodeled-items
- @newest_unmodeled_items.each do |item|
- localized_cache "items/#{item.id} modeling_progress updated_at=#{item.updated_at.to_i}" do
- cache "items/#{item.id} modeling_progress locale=#{I18n.locale} updated_at=#{item.updated_at.to_i}" do
%li{'data-item-id' => item.id}
= link_to image_tag(item.thumbnail_url), item, :class => 'image-link'
= link_to item, :class => 'header' do

View file

@ -1,11 +0,0 @@
module FragmentLocalization
def localize_fragment_key(key, locale)
if key.is_a?(Hash)
{:locale => locale}.merge(key)
elsif key.is_a?(String)
"#{key} #{locale}"
else
raise TypeError, "unexpected fragment key type: #{key.class}"
end
end
end