Patch #31384

Remove custom lazy loading of i18n files

Added by Pavel Rosický over 3 years ago. Updated about 3 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Code cleanup/refactoring
Target version:-

Description

i18n gem was updated in #29946 (4.1.0)

this caused a regression with these translations

     numbers:
       '1': One
       '2': Two
       '3': Three

     I18n.t('1', scope: [:numbers])

     Failure/Error: _key = _key.to_sym
     NoMethodError:
       undefined method `to_sym' for 2:Integer
       Did you mean?  to_s
     # ./lib/redmine/i18n.rb:206:in `block in lookup'
     # ./lib/redmine/i18n.rb:205:in `each'
     # ./lib/redmine/i18n.rb:205:in `inject'
     # ./lib/redmine/i18n.rb:205:in `lookup'
     # /usr/local/rvm/gems/ruby-2.5.3-railsexpress/gems/i18n-1.6.0/lib/i18n/backend/base.rb:32:in `translate'

the problem is in redmine, because it uses a custom backend that overrides the original behaviour and it wasn't updated accordingly

see the original PR https://github.com/ruby-i18n/i18n/pull/422
also this change doesn't work https://github.com/ruby-i18n/i18n/pull/469

attached patch fixes the problem by removing most of the custom backend in redmine

i18n.rb.patch Magnifier (2.85 KB) Pavel Rosický, 2019-05-17 16:38


Related issues

Related to Redmine - Feature #36728: Reintroduce lazy loading of i18n files Closed
Blocks Redmine - Feature #29946: Update i18n gem (~> 1.6.0) Closed

Associated revisions

Revision 18286
Added by Jean-Philippe Lang about 3 years ago

Removes lazy loading of i18n files for 18n 1.6.0 compat (#31384).

History

#1 Updated by Go MAEDA over 3 years ago

#2 Updated by Go MAEDA over 3 years ago

  • Target version set to 4.1.0

#3 Updated by Go MAEDA over 3 years ago

#4 Updated by Go MAEDA over 3 years ago

#5 Updated by Go MAEDA over 3 years ago

  • Target version deleted (4.1.0)

#6 Updated by Marius BALTEANU over 3 years ago

  • Assignee set to Jean-Philippe Lang
  • Target version set to 4.1.0

Jean-Philippe, please take a look at the patch proposed by Pavel as a fix to a problem that was introduced by me when we updated the i8n gem to 1.6.0 (#29946).

For me, the change looks good, especially because we drop quite a lot of custom code.

#7 Updated by Jean-Philippe Lang about 3 years ago

Marius BALTEANU wrote:

For me, the change looks good, especially because we drop quite a lot of custom code.

Sure but it also removes the feature that this custom code provides :-)

#8 Updated by Jean-Philippe Lang about 3 years ago

  • Subject changed from fix type-casted translation keys to Remove custom lazy loading of i18n files
  • Category set to Code cleanup/refactoring
  • Status changed from New to Closed
  • Target version deleted (4.1.0)

Patch committed.

#9 Updated by Pavel Rosický about 3 years ago

thanks for the feedback. You're right, i18n gem provides lazy loading for translations, but it loads all available translations at once.

the original redmine backend loaded only the current locale and this optimization was removed.

here's a benchmark on a clean redmine instance (without plugins)

  1.859000   1.515000   3.374000 (  3.379579) - load all locales
  0.079000   0.063000   0.142000 (  0.141866) - load the current locale (english)

on production all translations should be eager loaded, but on development the first request time is now significantly worse. Do you think it's worth to restore the optimization or improve it in the i18n gem?

#10 Updated by Go MAEDA 6 months ago

  • Related to Feature #36728: Reintroduce lazy loading of i18n files added

Also available in: Atom PDF