python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.29k stars 433 forks source link

Keep @modifiers when parsing locales #947

Closed madduck closed 1 year ago

madduck commented 1 year ago

Locale modifiers ("@variants") are described in the GNU gettext documentation like this:

The ‘@variant’ can denote any kind of characteristics that is not already implied by the language ll and the country CC. […] It can also denote a dialect of the language, …

Wherein Babel previously would discard these, this patch stores the modifier information in the Locale objects, handling string representation accordingly.

Not implemented is the lookup of a meaningful description of modifiers, but instead — for now — an identity mapping is provided.

All tests pass. Furthermore, integration with flask-babel has been verified to work.

Resolves: #946 Signed-off-by: martin f. krafft madduck@madduck.net

madduck commented 1 year ago

@akx Thank you for your time. I addressed most of your comments, and left an open question in the above. Happy to proceed any way, just let me know what you prefer.

codecov[bot] commented 1 year ago

Codecov Report

Merging #947 (83188f0) into master (6bf793a) will decrease coverage by 0.02%. The diff coverage is 93.10%.

@@            Coverage Diff             @@
##           master     #947      +/-   ##
==========================================
- Coverage   90.91%   90.89%   -0.02%     
==========================================
  Files          25       25              
  Lines        4327     4340      +13     
==========================================
+ Hits         3934     3945      +11     
- Misses        393      395       +2     
Impacted Files Coverage Δ
babel/core.py 96.31% <93.10%> (-0.45%) :arrow_down:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

madduck commented 1 year ago

Sorry for the failing tests, was due to the 4/5 tuple return depending on modifier==None. I am not actually very sure it's a good idea, but I see your point. Fixed now.