Coverage for gws-app/gws/spec/generator/strings.py: 17%
23 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1import re
3from . import base, util
6def collect(gen: base.Generator):
7 dct = {}
9 for spec in gen.specs:
10 typ = gen.types[spec['uid']]
11 if not typ.name:
12 continue
13 _add_string(dct, typ.name, typ.doc)
14 if typ.enumDocs:
15 for k, v in typ.enumDocs.items():
16 _add_string(dct, typ.name + '.' + k, v)
18 for path in util.find_files(gen.selfDir + '/..', pattern=r'/strings.+?\.ini$', deep=False):
19 base.log.debug(f'parsing strings from {path!r}')
20 util.parse_ini(dct, util.read_file(path))
22 return dct
25def _add_string(dct, uid, doc):
26 """Add a docstring to the dict.
28 The language is assumed en, unless the string starts with a [xx]
29 language code.
30 """
32 lang = 'en'
33 m = re.match(r'^\[(\w\w)](.+)$', doc)
34 if m:
35 lang = m.group(1)
36 doc = m.group(2).strip()
37 dct.setdefault(lang, {})[uid] = doc.replace('\\n', '\n')