gettext: implement gettext and ngettext

By wrapping the C counterparts
pull/229/merge
Riccardo Magliocchetti 2017-11-05 11:25:02 +01:00 zatwierdzone przez Paul Sokolovsky
rodzic 91d176d57a
commit 6b93948472
3 zmienionych plików z 35 dodań i 3 usunięć

Wyświetl plik

@ -0,0 +1,14 @@
import ffilib
libc = ffilib.libc()
gettext_ = libc.func("s", "gettext", "s")
ngettext_ = libc.func("s", "ngettext", "ssL")
def gettext(message):
return gettext_(message)
def ngettext(singular, plural, n):
return ngettext_(singular, plural, n)

Wyświetl plik

@ -1,3 +1,5 @@
srctype=dummy
type=module
version = 0.0.1
srctype = micropython-lib
type = module
version = 0.1
author = Riccardo Magliocchetti
depends = ffilib

Wyświetl plik

@ -0,0 +1,16 @@
import gettext
msg = gettext.gettext('yes')
assert msg == 'yes'
msg = gettext.ngettext('one', 'two', 1)
assert msg == 'one'
msg = gettext.ngettext('one', 'two', 2)
assert msg == 'two'
msg = gettext.ngettext('one', 'two', 0)
assert msg == 'two'
msg = gettext.ngettext('one', 'two', 'three')
assert msg == 'two'