Skip to content

Commit c2462f0

Browse files
committed
Added docs for i18n and bumped version to 1.10.0
- Added docs for peng3d.i18n module - Bumped version from 1.9.0a1 to 1.10.0 - Updated versioning schema to prevent PyPI from marking all releases as beta - Updated tox version in use - Added official support for Python 3.5 and 3.6, 3.6 is now the main version
1 parent bb24c53 commit c2462f0

File tree

12 files changed

+126
-8
lines changed

12 files changed

+126
-8
lines changed

docs/api/peng3d.i18n.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
``peng3d.i18n`` - Lightweight Translation Manager
3+
=================================================
4+
5+
.. automodule:: peng3d.i18n
6+
:members:
7+
:synopsis: Lightweight Translation Manager

docs/api/peng3d.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Note that for compatibility reasons, peng3d.window is not available by default a
2828
gui/text
2929
gui/slider
3030
peng3d.resource
31+
peng3d.i18n
3132
peng3d.model
3233
peng3d.camera
3334
peng3d.world

docs/configoption.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,27 @@ Resource Options
241241

242242
By default set to 1024.
243243

244+
.. _cfg-i18n:
245+
246+
Translation Options
247+
-------------------
248+
249+
.. confval:: i18n.enable
250+
251+
Enables or Disables the i18n module.
252+
253+
By default enabled.
254+
255+
.. confval:: i18n.lang
256+
257+
Determines the default language selected upon startup.
258+
259+
Note that setting this config option after creating the first window will have
260+
no effect. Use :py:meth:`~peng3d.i18n.TranslationManager.setLang()` instead.
261+
262+
Currently defaults to ``en``\ , but may be changed to operating system language
263+
in the future.
264+
244265
Event Options
245266
-------------
246267

docs/events.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,25 @@ signal that either the manager itself was modified or a resource was changed.
163163

164164
Additional parameters are ``name`` set to the name of the model.
165165

166+
.. _events-i18n:
167+
168+
``peng3d:i18n.*`` Events Category
169+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
170+
171+
.. seealso::
172+
173+
See :py:class:`~peng3d.i18n.TranslationManager()` for more information about the translation system.
174+
175+
.. peng3d:event:: peng3d.i18n.set_lang
176+
177+
Sent whenever the default language is set.
178+
179+
Note that this event is sent regardless of whether or not the language actually changed.
180+
181+
Additional parameters are ``i18n``\ , set to the translation manager, and ``lang``
182+
set to the new language.
183+
184+
166185
``peng3d:keybind.*`` Events Category
167186
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
168187

peng3d/i18n.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,32 @@
3131

3232
from .util import ActionDispatcher
3333

34+
# TODO: add test cases for translations
3435
class TranslationManager(ActionDispatcher):
36+
"""
37+
Manages sets of translation files in multiple languages.
38+
39+
This Translation System uses language codes to identify languages, there is
40+
no requirement to follow a specific standard, but it is recommended to use
41+
simple 2-digit codes like ``en`` and ``de``\ , adding an underscore to
42+
define sub-languages like ``en_gb`` and ``en_us``\ .
43+
44+
Whenever a new translation file is needed, it will be parsed and then cached.
45+
This speeds up access times and also practically eliminates load times when
46+
switching languages.
47+
48+
Several events are sent by this class, see :ref:`events-i18n`\ .
49+
50+
Most of these events are also sent as actions, these actions are described
51+
in the methods that cause them.
52+
53+
There are also severale config options that determine the behaviour of this class.
54+
See :ref:`cfg-i18n` for more information.
55+
56+
57+
This Manager requires the :py:class:`~peng3d.resource.ResourceManager()` to
58+
be already initialized.
59+
"""
3560
def __init__(self,peng):
3661
if not peng.cfg["rsrc.enable"]:
3762
raise RuntimeError("ResourceManager needs to be enabled to use Translations")
@@ -48,6 +73,25 @@ def __init__(self,peng):
4873
self.setLang(self.peng.cfg["i18n.lang"])
4974

5075
def setLang(self,lang):
76+
"""
77+
Sets the default language for all domains.
78+
79+
For recommendations regarding the format of the language code, see
80+
:py:class:`TranslationManager`\ .
81+
82+
Note that the ``lang`` parameter of both :py:meth:`translate()` and
83+
:py:meth:`translate_lazy()` will override this setting.
84+
85+
Also note that the code won't be checked for existence or plausibility.
86+
This may cause the fallback strings to be displayed instead if the language
87+
does not exist.
88+
89+
Calling this method will cause the ``setlang`` action and the
90+
:peng3d:event`peng3d:i18n.set_lang` event to be triggered. Note that both
91+
action and event will be triggered even if the language did not actually change.
92+
93+
This method also automatically updates the :confval:`i18n.lang` config value.
94+
"""
5195
self.lang = lang
5296
self.peng.cfg["i18n.lang"] = lang
5397

@@ -58,6 +102,17 @@ def setLang(self,lang):
58102
self.peng.sendEvent("peng3d:i18n.set_lang",{"lang":self.lang,"i18n":self})
59103

60104
def discoverLangs(self,domain="*"):
105+
"""
106+
Generates a list of languages based on files found on disk.
107+
108+
The optional ``domain`` argument may specify a domain to use when checking
109+
for files. By default, all domains are checked.
110+
111+
This internally uses the :py:mod:`glob` built-in module and the
112+
:confval:`i18n.lang.format` config option to find suitable filenames.
113+
It then applies the regex in :confval:`i18n.discover_regex` to extract the
114+
language code.
115+
"""
61116
rsrc = self.peng.cfg["i18n.lang.format"].format(domain=domain,lang="*")
62117
pattern = self.peng.rsrcMgr.resourceNameToPath(rsrc,self.peng.cfg["i18n.lang.ext"])
63118
files = glob.iglob(pattern)

peng3d/util/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ def __setitem__(self,*args):
6363
c = self.callback()(self)
6464

6565
def register_pyglet_handler(peng,func,event,raiseErrors=False):
66+
"""
67+
Registers the given pyglet-style event handler for the given pyglet event.
68+
69+
This function allows pyglet-style event handlers to receive events bridged
70+
through the peng3d event system. Internally, this function creates a lambda
71+
function that decodes the arguments and then calls the pyglet-style event handler.
72+
73+
The ``raiseErrors`` flag is passed through to the peng3d event system and will
74+
cause any errors raised by this handler to be ignored.
75+
76+
.. seealso::
77+
See :py:meth:`~peng3d.peng.Peng.addEventListener()` for more information.
78+
"""
6679
peng.addEventListener("pyglet:%s"%event,(lambda data:func(*data["args"])),raiseErrors)
6780

6881
class ActionDispatcher(object):

peng3d/version.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424

2525
__all__ = ["VERSION","RELEASE"]
2626

27-
VERSION = "1.9.0a1"
27+
VERSION = "1.10.0"
2828
"""
29-
Full version number of format ``MAJOR.MINOR.BUGFIX(a|b|pre)SUBRELEASE`` where major is increased only on very major feature changes.
29+
Full version number of format ``MAJOR.MINOR.BUGFIX`` where major is increased only on very major feature changes.
3030
Minor is changed if a new feature is introduced or an API change is made, while bugfix only changes if an important fix for a bug needs to be provided before the next release.
31-
Either a, b, or pre follows depending on the type of release, e.g. a for alpha, b for beta and pre for prereleases.
3231
3332
Used to display the version in the title of the documentation.
3433
@@ -38,9 +37,9 @@
3837
3938
"""
4039

41-
RELEASE = "1.9.0"
40+
RELEASE = "1.10.0"
4241
"""
43-
Same as :py:data:`VERSION` but without the subrelease.
42+
Currently the same as :py:data:`VERSION`\ .
4443
4544
Used to display the version on the top-right of the documentation.
4645
"""

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ bidict==0.14.2
22
future==0.15.2
33
#pyglet==1.3.0a1
44
https://bitbucket.org/pyglet/pyglet/get/f48574e6c61c.zip
5-
tox==2.3.1
5+
tox==3.7.0
66
virtualenv==15.0.2
77
pytest==3.2.3
88
py>=1.4.33

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def load_module(name):
9797
"Programming Language :: Python :: 3",
9898
"Programming Language :: Python :: 3.3",
9999
"Programming Language :: Python :: 3.4",
100+
"Programming Language :: Python :: 3.5",
101+
"Programming Language :: Python :: 3.6",
100102

101103
"Topic :: Games/Entertainment",
102104
"Topic :: Multimedia :: Graphics :: 3D Rendering",

tests/test_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import peng3d
3030

31-
VERSION_PATTERN = r"[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{0,2}[a-z][0-9]{1,2}"
31+
VERSION_PATTERN = r"[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{0,2}"
3232

3333
RELEASE_PATTERN = r"[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{0,2}"
3434

0 commit comments

Comments
 (0)