Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport (#45169): Allow all available locales for template lookups. #47494

Conversation

bendilley
Copy link

This is a proposed backport of #45169 to v7.0, cherry-picking @oneiros's commit below. Our use case of per-tenant locales is pretty much identical and we'd greatly appreciate the backport while we're waiting for v7.1 to be released.

Following the discussion here:
https://github.com/rails/rails/pull/44174/files#r785160819

Background: The i18n gem is relatively lax when it comes to naming locales. It does not enforce any standard. Thus it is possible to have e.g. per tenant locales (think en_tenant1, en_tenant2 etc.). This also worked for translated templates up until rails 6.1.

Rails 7 changed the template lookup and enforced a naming scheme for locales. This poses a problem for legacy apps that use non-standard locale names.

This commit changes the way locale names are detected in template file names. In addition to the previously used regexp it also allows all known locales from
I18n.available_locales.

This makes it backwards compatible to rails 7.0
behavior while also allowing non-standard locale names. Thanks to jvillarejo for the great idea.

Also introduce the usage of Regexp.union, a wonderful suggestion by casperisfine.

(cherry picked from commit 12c1289)

Motivation / Background

This Pull Request has been created because [REPLACE ME]

Detail

This Pull Request changes [REPLACE ME]

Additional information

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot bot added the actionview label Feb 24, 2023
@zzak
Copy link
Member

zzak commented Mar 3, 2023

Sorry just a passing comment, but we generally only backport the merge commit:
https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#backporting

…es_for_template_lookup

Allow all available locales for template lookups

(cherry picked from commit a5b2b61)
@bendilley bendilley force-pushed the backport-all-available-locales-for-template-lookup branch from 5f2e842 to f0d5ffd Compare March 3, 2023 09:08
@bendilley
Copy link
Author

Thank you for the pointer @zzak - I reset to 7-0-stable and cherry-picked the merge commit as advised.

@zzak zzak added the ready PRs ready to merge label Mar 3, 2023
@zzak zzak changed the title Allow all available locales for template lookups. Backport (#45169): Allow all available locales for template lookups. Mar 3, 2023
@rafaelfranca rafaelfranca merged commit ce22966 into rails:7-0-stable Mar 3, 2023
@bendilley
Copy link
Author

Many thanks @rafaelfranca and @zzak

@davegudge davegudge deleted the backport-all-available-locales-for-template-lookup branch May 26, 2023 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionview ready PRs ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants