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

Accept language on 2 or 5 chars #3

Merged
merged 1 commit into from
Mar 21, 2022
Merged

Accept language on 2 or 5 chars #3

merged 1 commit into from
Mar 21, 2022

Conversation

j0k3r
Copy link
Member

@j0k3r j0k3r commented Mar 9, 2022

Accept en, fr, etc.. but also de-DE, en-US, etc.
Also replace dead image in tests by a real image.
And use Regex to validate the language

Related:

@j0k3r j0k3r requested review from nicosomb, Kdecherf and tcitworld March 9, 2022 10:58
Copy link
Member

@Kdecherf Kdecherf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could replace mb_strlen calls with this regex:

preg_match('/^((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<region>[A-Za-z]{2}|[0-9]{3}))?)$/', $language);

It is incomplete but should work for almost all cases.

References:

@j0k3r j0k3r requested review from Kdecherf and tcitworld March 14, 2022 13:55
@j0k3r
Copy link
Member Author

j0k3r commented Mar 14, 2022

@Kdecherf I'm not sure about the regex, fr is not allowed: https://3v4l.org/aq5Gl

@Kdecherf
Copy link
Member

@j0k3r hm the results I see on your snippet are expected

@j0k3r
Copy link
Member Author

j0k3r commented Mar 14, 2022

Hmm does the comparison in my last commit is ok then?

Copy link
Member

@Kdecherf Kdecherf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex in last commit looks good, I let you squash before merging

Accept `en`, `fr`, etc.. but also `de-DE`, `en-US`, etc.
Also replace dead image in _tests_ by a real image.
And use Regex to validate the language
@j0k3r j0k3r requested review from Kdecherf and nicosomb March 21, 2022 19:26
@j0k3r j0k3r merged commit 1f74a5c into master Mar 21, 2022
@j0k3r j0k3r deleted the fix/language branch March 21, 2022 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants