Actionpack-page_caching with i18n

Hi,

I need to get some pages to be super fast and actionpack-page_caching is a doing the job but I also need to get i18n.

So I am executing the translate in a js controller via the gem i18n-js, so theorically, the translation is excute on the client side after it get the page.

But it’s not working, is someone has encountered a similar problem: cache page + i18n ?

Best regards.

I don’t know actionpack-page_caching and we don’t use i18n-js as our translation is performed server-side. We override cache as shown below to automatically include the locale in the key (don’t know where the idea was initially taken from):

module CacheHelper
  # Always using current I18n.locale to cache things.
  def cache(name = {}, options = {}, &block)
    name_with_locale = [name].flatten << I18n.locale.to_s
    super(name_with_locale, options, &block)
  end
end

Ok, thanks to answer.

We override cache as shown below to automatically include the locale in the key

However, this only works when calling cache in views. How to ensure the locale is included when calling Rails.cache.fetch? It looks like it might be possible to override ActiveSupport::Cache::Store::normalize_key but not sure how. And for some reason it is a private method. For instance if we use an ActiveSupport::Cache::MemoryStore, how to ensure that caching is always separate per locale?