reutenauer / polyglossia

An alternative to Babel for XeLaTeX and LuaLaTeX
http://www.ctan.org/pkg/polyglossia
MIT License
185 stars 52 forks source link

Make tools/bcp47.py compatible with python3 #649

Open stephen-huan opened 5 days ago

stephen-huan commented 5 days ago

python2 has been depreciated since 2020. It'd be useful if I could use this file for some translation work in pandoc, and I'm writing code in python3. The first commit makes the script usable from python3, while keeping compatibility with python2 (>= 2.6). The next two commits are some minor nits.

The third commit fixes a bug, currently, babelname2bcp47 maps chinese to zh-TW since a dictionary with duplicate keys takes the last value. Babel uses chinese to mean zh, so the duplicates have been removed. The key sa-Deva is also duplicated in bcp472lang, but the value is the same for both so the resulting semantics are the same.

The fourth commit adds some missing bcp47 codes to bcp472lang.

Udi-Fogiel commented 4 days ago

Thanks! I'm actually planing to port this script to lua, as I would like to have less dependencies. Will that be a problem for your projects?

Note that I'm less familiar with this script, as I did not wrote it nor used it before, so unless @jspitz beats me to it it will probably take me a couple of days to find a time to review this PR.

stephen-huan commented 4 days ago

Thanks! I'm actually planing to port this script to lua, as I would like to have less dependencies. Will that be a problem for your projects?

In the short term, I base my work off my fork of polyglossia, so it wouldn't directly affect me. In the long run, I've been thinking about moving to lua myself (for the same reason, pandoc embeds a lua interpreter by default). So in either case, you shouldn't need to worry about my (relatively niche) use case.

Note that I'm less familiar with this script, as I did not wrote it nor used it before, so unless @jspitz beats me to it it will probably take me a couple of days to find a time to review this PR.

No worries, I made the modifications and thought I might as well upstream the fixes.