Skip to content

Commit 6b93948

Browse files
xrmxpfalcon
authored andcommitted
gettext: implement gettext and ngettext
By wrapping the C counterparts
1 parent 91d176d commit 6b93948

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

gettext/gettext.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import ffilib
2+
3+
libc = ffilib.libc()
4+
5+
gettext_ = libc.func("s", "gettext", "s")
6+
ngettext_ = libc.func("s", "ngettext", "ssL")
7+
8+
9+
def gettext(message):
10+
return gettext_(message)
11+
12+
13+
def ngettext(singular, plural, n):
14+
return ngettext_(singular, plural, n)

gettext/metadata.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
srctype=dummy
2-
type=module
3-
version = 0.0.1
1+
srctype = micropython-lib
2+
type = module
3+
version = 0.1
4+
author = Riccardo Magliocchetti
5+
depends = ffilib

gettext/test_gettext.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import gettext
2+
3+
msg = gettext.gettext('yes')
4+
assert msg == 'yes'
5+
6+
msg = gettext.ngettext('one', 'two', 1)
7+
assert msg == 'one'
8+
9+
msg = gettext.ngettext('one', 'two', 2)
10+
assert msg == 'two'
11+
12+
msg = gettext.ngettext('one', 'two', 0)
13+
assert msg == 'two'
14+
15+
msg = gettext.ngettext('one', 'two', 'three')
16+
assert msg == 'two'

0 commit comments

Comments
 (0)