We started to introduce fragment caching in our app as follows:
= render partial: "memberships/program",
collection: @programs,
cached: true
However the app is bilingual and when switching the language it keeps the data from the other language (e.g. both the English and French page show the text in English).
As a workaround to restore the correct language, the code above can be expanded as follows:
- @programs.each do |program|
- cache [I18n.locale, program] do
= render partial: "memberships/program",
locals: { program: program }
But this degrades the performance compared to the first snippet according to this article and is not as succint.
Is there any way to get back the performance and succinctness of the first snippet while taking into account I18n.locale
?