/
README
47 lines (32 loc) · 1.49 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
plural.py
An implementation of Mozilla's plural forms* in Python.
*Except rule 12, which differs in word order from Mozilla.
Usage:
import plural
translations = ("bird", "birds")
one = plural.pluralize(translations, 1, rulefor("en"))
print "There is one {0}".format(one)
two = plural.pluralize(translations, 2, rulefor("en"))
print "There are two {0}".format(two)
print "plural.py expects the following translations for Irish Gaeilge:"
print plural.explain(rulefor("ga"))
To make pluralservice work, Flask must be installed:
- install VirtualEnv (sudo easy_install virtualenv)
- create an environment (virtualenv env)
- switch to the environment (. env/bin/activate)
- install Flask (easy_install Flask)
The URLs are:
http://server/language/{langcode} - rulefor(langcode)
http://server/rule/{rule} - explain(rule)
http://server/pluralize - pluralize()
Pluralize expects the following query parameters:
w: a word form, such as "bird" or "birds" (repeated as many times as needed)
c: count, the number of "w" requested
r: rule, the rule to apply
Given that English is rule 1 (you can discover this by calling the /language/ service),
requesting the translation for 2 birds would be:
http://server/pluralize?w=bird&w=birds&c=2&rule=1
And the response would be:
{"count": 2, "word": "birds", "rule": 1}
Errors are reported by nulling the response value and including an error string:
{"count": 2, "word": null, "rule": 42, "error": "Invalid rule specified"}