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

Fixed #24063 -- Locale code validation too strict #3815

Closed
wants to merge 1 commit into from
Closed

Fixed #24063 -- Locale code validation too strict #3815

wants to merge 1 commit into from

Conversation

nijel
Copy link
Contributor

@nijel nijel commented Dec 30, 2014

The locale code can contain variant after @, so let's allow the
validation of it to pass.

@@ -1424,8 +1424,11 @@ def test_check_for_language(self):
self.assertTrue(check_for_language('en'))
self.assertTrue(check_for_language('en-us'))
self.assertTrue(check_for_language('en-US'))
self.assertTrue(check_for_language('be'))
self.assertTrue(check_for_language('be@latin'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add more tests? For example, "tr_TR.UTF-8", "tr_TR.UTF8" (without the dash), "de_DE.utf-8" (lowercase encoding), "sr_RS@latin", "sr_RS@12345".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added, but specifying charset is currently not supported (and IMHO does not make sense as Django enforces UTF-8 on locales).

@berkerpeksag
Copy link
Contributor

Could you also add a release note to docs/releases/1.8.txt and squash the commits into one?

@nijel
Copy link
Contributor Author

nijel commented Jan 5, 2015

Added release note and squashed commits as well.

@berkerpeksag
Copy link
Contributor

buildbot, test this please.

self.assertTrue(check_for_language('be'))
self.assertTrue(check_for_language('be@latin'))
self.assertTrue(check_for_language('sr-RS@latin'))
self.assertTrue(check_for_language('sr-RS@12345'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there is no standard for @modifier, but I'd reject all digits ones. Or to be more strict, we can only accept iqtelif, euro, cyrillic, abegede, devanagari, latin: https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED;h=9bf2a4f3840925c38bdefeaba28d2077835c7f07;hb=HEAD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've quite intentionally kept it matching anything (same as language or country codes), but we can indeed be more strict.

Anyway there can be more in use, for example ca@valencia: https://github.com/translate/translate/blob/master/translate/lang/data.py#L44

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway I don't think that hardcoding the list is good idea, for example here is list of variants available on my system:

# sed -n '/@/ s/.*@\(.*\) .*/\1/p' /usr/share/i18n/SUPPORTED | sort -u
abegede
cyrillic
devanagari
euro
iqtelif
latin
saaho
valencia

@collinanderson
Copy link
Contributor

buildbot, test this please

@@ -374,6 +374,10 @@ Internationalization
reusable apps. It also allows overriding those custom formats in your main
Django project.

* Django now allows to use locale variants as supported by Gettext. These are
Copy link
Member

Choose a reason for hiding this comment

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

chop "as"
gettext (no caps)

@timgraham
Copy link
Member

Release note needs to be moved to 1.9 at this point.

@nijel
Copy link
Contributor Author

nijel commented Mar 26, 2015

Okay, I've rebased changes on current master, moved the release notes and made suggested improvements in them.

Any chance to get this small change merged soon?

@@ -146,6 +146,10 @@ Internationalization
* The :func:`django.views.i18n.javascript_catalog` view now works correctly
if used multiple times with different configurations on the same page.

* Django now allows to use locale variants supported by Gettext. These are
Copy link
Member

Choose a reason for hiding this comment

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

  1. "Django" is a bit redundant give these are the Django release notes. How about "You can now use...". Also, can you add details about where in Django these locale variants can be used?
  2. "gettext" shouldn't be capitalized

The locale code can contain variant after @, so let's allow the
validation of it to pass.

Also add more complete coverage for language code variants.

Signed-off-by: Michal Čihař <michal@cihar.com>
@timgraham
Copy link
Member

buildbot, add to whitelist.

@timgraham
Copy link
Member

merged in 76d26d8, thanks!

@timgraham timgraham closed this Apr 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants