开发者

How to sort collections based on current user locale on a Django site

开发者 https://www.devze.com 2023-03-09 19:02 出处:网络
I need to sort a collection of objects by autf-8 string property (built via ActiveRecord).Currently the code is so开发者_JAVA百科rting by ASCII order via the order_by method, however this needs to be

I need to sort a collection of objects by a utf-8 string property (built via ActiveRecord). Currently the code is so开发者_JAVA百科rting by ASCII order via the order_by method, however this needs to be changed to locale.strcoll. Unfortunately using the built in locale functionality requires changing the culture for the entire application, not just the current request.

I've looked at the Babel library but it does not appear to provide the functionality I need.

The only other option I have been able to find is pyICU, however getting the ICU libraries installed in my environment will prevent this as a viable solution.

Are there any other options?


The solution I ended up taking is just converting the utf-8 string to ASCII and stripping the diacritics just for the sort operation. Not ideal but it ended up working for this specific case.

0

精彩评论

暂无评论...
验证码 换一张
取 消