Skip to content

Instantly share code, notes, and snippets.

@imankulov
Created December 8, 2015 21:53
Show Gist options
  • Save imankulov/866660acdd90cb4004c7 to your computer and use it in GitHub Desktop.
Save imankulov/866660acdd90cb4004c7 to your computer and use it in GitHub Desktop.
CLDR test
#!/bin/bash
function create_venv() {
test -d env || virtualenv env
source ./env/bin/activate
pip install -q -U pip
}
function babel_from_pip() {
echo "=================================================="
echo "Running tests with Babel 2.1.1, installed with pip"
echo "=================================================="
pip uninstall -q -y Babel
pip install -q Babel==2.1.1
}
function babel_from_git() {
echo "=================================================="
echo "Running tests with Babel installed from git"
echo "=================================================="
pip uninstall -q -y Babel
test -d babel || git clone -q https://github.com/python-babel/babel.git
test -f babel/cldr/core-26.zip || ( cd babel && python setup.py import_cldr ) &> /dev/null
pip install -q -e ./babel
}
function test_babel() {
cat <<EOF > testfile.py
from babel import Locale, plural
from pprint import pprint
for lang in ['ru', 'pl', 'hu', 'tr']:
plural_form = Locale.parse(lang).plural_form
print("-" * 50)
print(lang)
print("-" * 50)
print("Rules")
pprint(plural_form.rules)
print("Gettext")
print(plural.to_gettext(plural_form))
print("")
EOF
python testfile.py
}
create_venv
babel_from_pip
test_babel
babel_from_git
test_babel
==================================================
Running tests with Babel 2.1.1, installed with pip
==================================================
--------------------------------------------------
ru
--------------------------------------------------
Rules
{'few': 'n mod 10 in 2..4 and n mod 100 not in 12..14',
'many': 'n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14',
'one': 'n mod 10 is 1 and n mod 100 is not 11'}
Gettext
nplurals=4; plural=(((((n % 10) >= 2 && (n % 10) <= 4)) && (!(((n % 100) >= 12 && (n % 100) <= 14)))) ? 1 : ((((n % 10) == 0) || (((n % 10) >= 5 && (n % 10) <= 9))) || (((n % 100) >= 11 && (n % 100) <= 14))) ? 2 : (((n % 10) == 1) && ((n % 100) != 11)) ? 0 : 3)
--------------------------------------------------
pl
--------------------------------------------------
Rules
{'few': 'n mod 10 in 2..4 and n mod 100 not in 12..14',
'many': 'n is not 1 and n mod 10 in 0..1 or n mod 10 in 5..9 or n mod 100 in 12..14',
'one': 'n is 1'}
Gettext
nplurals=4; plural=(((((n % 10) >= 2 && (n % 10) <= 4)) && (!(((n % 100) >= 12 && (n % 100) <= 14)))) ? 1 : ((((n != 1) && (((n % 10) >= 0 && (n % 10) <= 1))) || (((n % 10) >= 5 && (n % 10) <= 9))) || (((n % 100) >= 12 && (n % 100) <= 14))) ? 2 : (n == 1) ? 0 : 3)
--------------------------------------------------
hu
--------------------------------------------------
Rules
{}
Gettext
nplurals=1; plural=(0)
--------------------------------------------------
tr
--------------------------------------------------
Rules
{}
Gettext
nplurals=1; plural=(0)
==================================================
Running tests with Babel installed from git
==================================================
--------------------------------------------------
ru
--------------------------------------------------
Rules
{'few': 'v in 0 and i mod 10 in 2..4 and i mod 100 not in 12..14',
'many': 'v in 0 and i mod 10 in 0 or v in 0 and i mod 10 in 5..9 or v in 0 and i mod 100 in 11..14',
'one': 'v in 0 and i mod 10 in 1 and i mod 100 not in 11'}
Gettext
nplurals=4; plural=(((((v == 0)) && (((i % 10) >= 2 && (i % 10) <= 4))) && (!(((i % 100) >= 12 && (i % 100) <= 14)))) ? 1 : (((((v == 0)) && (((i % 10) == 0))) || (((v == 0)) && (((i % 10) >= 5 && (i % 10) <= 9)))) || (((v == 0)) && (((i % 100) >= 11 && (i % 100) <= 14)))) ? 2 : ((((v == 0)) && (((i % 10) == 1))) && (!(((i % 100) == 11)))) ? 0 : 3)
--------------------------------------------------
pl
--------------------------------------------------
Rules
{'few': 'v in 0 and i mod 10 in 2..4 and i mod 100 not in 12..14',
'many': 'v in 0 and i not in 1 and i mod 10 in 0..1 or v in 0 and i mod 10 in 5..9 or v in 0 and i mod 100 in 12..14',
'one': 'i in 1 and v in 0'}
Gettext
nplurals=4; plural=(((((v == 0)) && (((i % 10) >= 2 && (i % 10) <= 4))) && (!(((i % 100) >= 12 && (i % 100) <= 14)))) ? 1 : ((((((v == 0)) && (!((i == 1)))) && (((i % 10) >= 0 && (i % 10) <= 1))) || (((v == 0)) && (((i % 10) >= 5 && (i % 10) <= 9)))) || (((v == 0)) && (((i % 100) >= 12 && (i % 100) <= 14)))) ? 2 : (((i == 1)) && ((v == 0))) ? 0 : 3)
--------------------------------------------------
hu
--------------------------------------------------
Rules
{'one': 'n in 1'}
Gettext
nplurals=2; plural=(((n == 1)) ? 0 : 1)
--------------------------------------------------
tr
--------------------------------------------------
Rules
{'one': 'n in 1'}
Gettext
nplurals=2; plural=(((n == 1)) ? 0 : 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment