ruby-i18n / i18n

Internationalization (i18n) library for Ruby
MIT License
976 stars 408 forks source link

Return same string object when no interpolations were made #649

Closed fatkodima closed 1 year ago

fatkodima commented 1 year ago

See for the details - https://github.com/rails/rails/issues/47421

Even when there are no interpolations, gsub turns SafeBuffer into a String - https://github.com/rails/rails/blob/6af9cba73db6296ab9aec7dbeae1e193ea69f09f/activesupport/lib/active_support/core_ext/string/output_safety.rb#L169 So we need to preserve the original "string" object.

fatkodima commented 1 year ago

Not directly related: But isn't it too costly to allocate a new regexp via Regexp.union(config.interpolation_patterns) each time interpolation is done?

radar commented 1 year ago

Could we store that interpolation regex object so that it’s not recalculated every call? Possibly on the config object itself?

fatkodima commented 1 year ago

That is done on the other PR you just commented.

radar commented 1 year ago

Attempted to resolve the conflicts here after the other PR was merged in to master. Hope I did it right 🤞

fatkodima commented 1 year ago

Resolved conflicts.

radar commented 1 year ago

Thank you!

jrafanie commented 1 year ago

FYI, if you're using gettext_i18n_rails, you'll need to update to 1.10.1+ which plays nicer with this change in i18n 1.13.0.

See also https://github.com/grosser/gettext_i18n_rails/pull/196