Do not fail workflow if sunshine.po doesn't exist
- Add proper keywords for boost::locale - Minor documentation updates about localization
This commit is contained in:
parent
ceb7f5f41a
commit
b0a02a5985
3 changed files with 54 additions and 23 deletions
|
|
@ -13,6 +13,7 @@ import os
|
|||
import subprocess
|
||||
|
||||
project_name = 'Sunshine'
|
||||
project_owner = 'SunshineStream'
|
||||
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
root_dir = os.path.dirname(script_dir)
|
||||
|
|
@ -37,22 +38,30 @@ target_locales = [
|
|||
def x_extract():
|
||||
"""Executes `xgettext extraction` in subprocess."""
|
||||
|
||||
pot_filepath = os.path.join(locale_dir, f'{project_name.lower()}.po')
|
||||
|
||||
commands = [
|
||||
'xgettext',
|
||||
'--keyword=translate:1,1t',
|
||||
'--keyword=translate:1c,2,2t',
|
||||
'--keyword=translate:1,2,3t',
|
||||
'--keyword=translate:1c,2,3,4t',
|
||||
'--keyword=gettext:1',
|
||||
'--keyword=pgettext:1c,2',
|
||||
'--keyword=ngettext:1,2',
|
||||
'--keyword=npgettext:1c,2,3',
|
||||
f'--default-domain={project_name.lower()}',
|
||||
f'--output={os.path.join(locale_dir, project_name.lower() + ".po")}',
|
||||
f'--output={pot_filepath}',
|
||||
'--language=C++',
|
||||
'--boost',
|
||||
'--from-code=utf-8',
|
||||
'-F',
|
||||
f'--msgid-bugs-address=github.com/{project_name.lower()}',
|
||||
f'--copyright-holder={project_name}',
|
||||
f'--msgid-bugs-address=github.com/{project_owner.lower()}/{project_name.lower()}',
|
||||
f'--copyright-holder={project_owner}',
|
||||
f'--package-name={project_name}',
|
||||
'--package-version=v0'
|
||||
]
|
||||
|
||||
pot_filepath = os.path.join(locale_dir, f'{project_name.lower()}.po')
|
||||
|
||||
extensions = ['cpp', 'h', 'm', 'mm']
|
||||
|
||||
# find input files
|
||||
|
|
@ -66,23 +75,26 @@ def x_extract():
|
|||
print(commands)
|
||||
subprocess.check_output(args=commands, cwd=root_dir)
|
||||
|
||||
# fix header
|
||||
body = ""
|
||||
with open(file=pot_filepath, mode='r') as file:
|
||||
for line in file.readlines():
|
||||
if line != '"Language: \\n"\n': # do not include this line
|
||||
if line == '# SOME DESCRIPTIVE TITLE.\n':
|
||||
body += f'# Translations template for {project_name}.\n'
|
||||
elif line.startswith('#') and 'YEAR' in line:
|
||||
body += line.replace('YEAR', str(year))
|
||||
elif line.startswith('#') and 'PACKAGE' in line:
|
||||
body += line.replace('PACKAGE', project_name)
|
||||
else:
|
||||
body += line
|
||||
try:
|
||||
# fix header
|
||||
body = ""
|
||||
with open(file=pot_filepath, mode='r') as file:
|
||||
for line in file.readlines():
|
||||
if line != '"Language: \\n"\n': # do not include this line
|
||||
if line == '# SOME DESCRIPTIVE TITLE.\n':
|
||||
body += f'# Translations template for {project_name}.\n'
|
||||
elif line.startswith('#') and 'YEAR' in line:
|
||||
body += line.replace('YEAR', str(year))
|
||||
elif line.startswith('#') and 'PACKAGE' in line:
|
||||
body += line.replace('PACKAGE', project_name)
|
||||
else:
|
||||
body += line
|
||||
|
||||
# rewrite pot file with updated header
|
||||
with open(file=pot_filepath, mode='w+') as file:
|
||||
file.write(body)
|
||||
# rewrite pot file with updated header
|
||||
with open(file=pot_filepath, mode='w+') as file:
|
||||
file.write(body)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
def babel_init(locale_code: str):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue