Skip to content

Commit c6085ee

Browse files
committed
Add code to extract byname and pronounce for translation
1 parent 1fe2a5a commit c6085ee

File tree

1 file changed

+96
-13
lines changed

1 file changed

+96
-13
lines changed

util/skycultures/generate-pot.py

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,42 @@ def process_cons_or_asterism(array, obj_type, pot, sc_name):
164164
if native and obj_name == '':
165165
obj_name = native
166166

167-
if english:
168-
# Don't extract items that are already translated in other places
169-
if not english in common_names:
170-
comment = f'{sc_name} {obj_type}'
171-
if native:
172-
comment += f', native: {native}'
167+
if 'pronounce' in name:
168+
pronounce = name['pronounce']
169+
if len(pronounce) == 0:
170+
pronounce = None
171+
else:
172+
pronounce = None
173+
174+
if 'byname' in name:
175+
byname = name['byname']
176+
if len(byname) == 0:
177+
byname = None
178+
else:
179+
byname = None
180+
181+
comment = f'{sc_name} {obj_type}'
182+
if native:
183+
comment += f', native: {native}'
173184

174-
if 'pronounce' in name and len(name['pronounce']) != 0:
175-
comment += ', pronounce: ' + name['pronounce']
185+
if pronounce:
186+
comment += ', pronounce: ' + name['pronounce']
187+
188+
if byname:
189+
comment += ', byname: ' + name['byname']
190+
191+
if 'translators_comments' in name:
192+
comment += '\n' + name['translators_comments']
193+
194+
context = None
195+
if 'context' in name:
196+
context = name['context']
176197

177-
if 'translators_comments' in name:
178-
comment += '\n' + name['translators_comments']
179198

180-
context = None
181-
if 'context' in name:
182-
context = name['context']
199+
# Extract 'english' string for translation (with context for uniqueness)
200+
if english:
201+
# Don't extract items that are already translated in other places
202+
if not english in common_names:
183203

184204
cons_ast_names.add(english)
185205

@@ -192,6 +212,42 @@ def process_cons_or_asterism(array, obj_type, pot, sc_name):
192212
pot.append(entry)
193213
else:
194214
print(f'{sky_culture}: warning: common_name property in {obj_type} "{obj_id}" has no English name', file=sys.stderr)
215+
216+
# Extract 'pronounce' string for translation (with context for uniqueness)
217+
if pronounce:
218+
# Don't extract items that are already translated in other places
219+
if not pronounce in common_names:
220+
221+
cons_ast_names.add(pronounce)
222+
223+
entry = polib.POEntry(comment = comment, msgid = pronounce, msgstr = "", msgctxt = context)
224+
if entry in pot:
225+
prev_entry = pot.find(entry.msgid, msgctxt = context)
226+
assert prev_entry
227+
prev_entry.comment += '\n' + comment
228+
else:
229+
pot.append(entry)
230+
#else:
231+
# print(f'{sky_culture}: info: common_name property in {obj_type} "{obj_id}" has no pronounce element', file=sys.stderr)
232+
233+
# Extract 'byname' string for translation (with context for uniqueness)
234+
if byname:
235+
# Don't extract items that are already translated in other places
236+
if not byname in common_names:
237+
238+
cons_ast_names.add(byname)
239+
240+
entry = polib.POEntry(comment = comment, msgid = byname, msgstr = "", msgctxt = context)
241+
if entry in pot:
242+
prev_entry = pot.find(entry.msgid, msgctxt = context)
243+
assert prev_entry
244+
prev_entry.comment += '\n' + comment
245+
else:
246+
pot.append(entry)
247+
#else:
248+
# print(f'{sky_culture}: info: common_name property in {obj_type} "{obj_id}" has no byname element', file=sys.stderr)
249+
250+
195251
else:
196252
print(f'{sky_culture}: warning: no common_name key in {obj_type} "{obj_id}"', file=sys.stderr)
197253

@@ -289,6 +345,8 @@ def process_names(objects, pot, sc_name):
289345
prev_entry.comment += '\n' + comment
290346
else:
291347
pot.append(entry)
348+
349+
# TODO: Add translation of pronounce tag!
292350

293351
def process_extra_names(objects, pot, sc_name):
294352
if 'context' in objects:
@@ -325,6 +383,31 @@ def process_extra_names(objects, pot, sc_name):
325383
else:
326384
pot.append(entry)
327385

386+
# pronounce is language dependant! The element is optional.
387+
if 'pronounce' in name:
388+
pronounce = name['pronounce']
389+
if len(pronounce) == 0:
390+
pronounce = None
391+
else:
392+
pronounce = None
393+
394+
if not pronounce:
395+
continue
396+
397+
comment = f'Pronunciation of zodiac sign or name of lunar mansion in {sc_name} sky culture'
398+
if ecomment:
399+
comment += '\n' + ecomment
400+
401+
entry = polib.POEntry(comment = comment, msgid = pronounce, msgstr = "", msgctxt = context)
402+
if entry in pot:
403+
prev_entry = pot.find(entry.msgid, msgctxt = context)
404+
assert prev_entry
405+
if comment:
406+
prev_entry.comment += '\n' + comment
407+
else:
408+
pot.append(entry)
409+
410+
328411
for sky_culture in sclist:
329412
data_path = os.path.join(SCDIR, sky_culture)
330413
index_file = os.path.join(data_path, 'index.json')

0 commit comments

Comments
 (0)