1 from logging
import info
2 from os
.path
import join
, exists
, dirname
3 from gettext
import translation
4 from pathlib
import Path
5 from ya2
.gameobject
import GameObject
9 def is_runtime(): return not exists('main.py')
13 par_path
= str(Path(__file__
).parent
.absolute())
14 is_appimage
= par_path
.startswith('/tmp/.mount_Pmachines')
15 return is_appimage
and par_path
.endswith('/usr/bin')
19 if not is_runtime(): return ''
20 if sys
.platform
== 'darwin':
21 return dirname(__file__
) + '/../Resources/'
22 # return dirname(__file__)
23 par_path
= str(Path(__file__
).parent
.absolute())
25 return str(Path(par_path
).absolute())
26 is_snap
= par_path
.startswith('/snap/')
27 is_snap
= is_snap
and par_path
.endswith('/x1')
29 return str(Path(par_path
).absolute())
31 curr_path
= dirname(__file__
)
32 info('current path: %s' % curr_path
)
33 return curr_path
+ '/'
36 class LangMgr(GameObject
):
38 def __init__(self
, lang
, domain
, dpath
):
39 GameObject
.__init
__(self
)
42 self
.dpath
= join(curr_path(), dpath
)
43 info('language: %s, %s' % (self
.domain
, self
.dpath
))
48 return [lang
[1] for lang
in self
.eng
.cfg
.lang_cfg
.languages
]
50 def set_lang(self
, lang
):
52 args
= lang
, self
.domain
, self
.dpath
53 info('setting language %s, %s, %s' % args
)
54 tra
= translation(self
.domain
, self
.dpath
, [lang
], fallback
=True)