-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add support to locales with lowdash in Resolver::PathParser #44174
Merged
jhawthorn
merged 1 commit into
rails:main
from
jguecaimburu:add_lowdash_support_to_path_parser_locale_regex
Feb 17, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Guten Morgen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't make this regex configurable? For example, we use a non-standard locale "global", it does not match this regular expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify why
global
is desirable over the default of not specifying a locale? I don't think that's a pattern we've seen or have tests for. Do you have:global
configured inI18n.available_locales
? I'd have expected everything to mostly follow ISO 639-1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example we use "global" virtual locale to distinguish US users and all other english speaking users. They use totally different views, but both english language at the same time. It's very easy to use .global.haml views for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that
rails-i18n
only supports ISO codes listed here but I haven't tried anything else. There could be a way to get around that. For Rubyi18n
, RFC4646 and RFC4647 compliance doesn't seem to be enforced.For your specific use case, can you explain the rationale behind using a non-standard locale
global
vs the standard which accepts a language and a region code?en-US
for US users,en
for all other english speaking users. That communicates that english is the language in both cases, but you have specific needs for the US region. Not sure what would be the right way to group contries, let's say "south-latam" vs "north-latam", but I can imagine variants in that case.If non-standard locales need to be supported for backward compatibility reasons, my impression is that using
I18n
config to build the regex would be safer than allowing a configurable regex, but there could be a performance tradeoff. Also, a refactor might be needed to avoid hacking the details back to the build regex method. Of course this is just an opinion, I don't have the full picture to make this call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global name selected exactly for countries grouping and we didn't want to deal with region that time. having only locale seemed very simple that time. also in my opinion different regions like en-us en-gb means different yml files but in our case global=en and only haml templates are different. honestly I wouldn't want to rename all our internals to en-us/en just for one regexp.
not an our case and pretty rare but what if I'd want to have imaginary locales like elf/goblin/ork.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem is that the behavior that anything you config in
I18n.available_locales
would work (intended or unintended) was working before.And in Rails 7 that behavior was removed.
This PR doesn't provide that behavior. It just adds
lowdash
support which is POSIX locale formatAlso I don't know about your application @catz. But maybe you could make it work if you use request
variant
global
I think that making the REGEX configurable has a lot of impact.
Maybe we should make that considers the I18n
available_locales
configuration ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jhawthorn any thoughts on this discussion? I can modify this PR if accepting any
I18n
config is desired. I'll need some direction in that case as some decisions were probably taken when the code was changed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the idea, @jvillarejo! request variant is suitable for our needs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect if we use only
I18n. available_locales
we'd likely have the same type of issue, with folks who use AV locals which aren't configured as available.I've merged this PR (thank you!) but if the lack of support is causing hardship would definitely consider a PR to support any available_locale OR the existing format 🙇♂️.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually encountered the same problem when trying to update an app to rails 7 that uses non-standard locale names. In this case it is because of multi-tenancy: The app hosts several tenants and uses i18n for per-tenant text changes and (sometimes) per-tenant templates.
Instead of burying this in an old discussion, I opted to implement the suggestion with
I18n.available_locales
here: #45169Any other solution that let's me keep the locale names would be appreciated just as well.