[UI] Refactor appdata.xml code and markup translatable text

This commit is contained in:
Calum Lind 2017-02-23 11:53:39 +00:00
parent 3529036f55
commit 4df88c0df3
5 changed files with 36 additions and 32 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@ _trial_temp
deluge/i18n/*/ deluge/i18n/*/
deluge.pot deluge.pot
*.desktop *.desktop
*.appdata.xml
.build_data* .build_data*
osx/app osx/app
RELEASE-VERSION RELEASE-VERSION

View File

@ -4,9 +4,9 @@
<metadata_license>CC0-1.0</metadata_license> <metadata_license>CC0-1.0</metadata_license>
<project_license>GPL-2.0+</project_license> <project_license>GPL-2.0+</project_license>
<translation type="gettext">deluge</translation> <translation type="gettext">deluge</translation>
<name>Deluge BitTorrent Client</name> <_name>Deluge BitTorrent Client</_name>
<developer_name>Deluge Team</developer_name> <_developer_name>Deluge Team</_developer_name>
<summary>Deluge is a lightweight, Free Software, cross-platform BitTorrent client.</summary> <_summary>Deluge is a lightweight, Free Software, cross-platform BitTorrent client.</_summary>
<url type="homepage">http://www.deluge-torrent.org/</url> <url type="homepage">http://www.deluge-torrent.org/</url>
<url type="bugtracker">http://dev.deluge-torrent.org</url> <url type="bugtracker">http://dev.deluge-torrent.org</url>
<description> <description>

View File

@ -80,11 +80,11 @@ def create_gettext_js(js_dir):
locations.append((os.path.basename(filename), lineno + 1)) locations.append((os.path.basename(filename), lineno + 1))
strings[string] = locations strings[string] = locations
gettext_tpl = '''GetText={maps:{},\ gettext_tpl = (
add:function(string,translation) {this.maps[string]=translation},\ 'GetText={maps:{},'
get:function(string) {if (this.maps[string]) {string=this.maps[string]} return string}} 'add:function(string,translation){this.maps[string]=translation},'
function _(string) {return GetText.get(string)} 'get:function(string){if (this.maps[string]){string=this.maps[string]} return string}};'
''' 'function _(string){return GetText.get(string)}')
gettext_file = os.path.join(os.path.dirname(js_dir), 'gettext.js') gettext_file = os.path.join(os.path.dirname(js_dir), 'gettext.js')
with open(gettext_file, 'w') as fp: with open(gettext_file, 'w') as fp:

View File

@ -53,12 +53,18 @@ for (dirpath, dirnames, filenames) in os.walk('deluge'):
filepath = os.path.join(dirpath, filename) filepath = os.path.join(dirpath, filename)
if os.path.splitext(filepath)[1] in ('.py', '.glade'): if os.path.splitext(filepath)[1] in ('.py', '.glade'):
to_translate.append(filepath) to_translate.append(filepath)
else:
if filename.endswith('.xml.in'):
gtxt_type = 'gettext/xml'
elif filename.endswith('.in'): elif filename.endswith('.in'):
call(['intltool-extract', '--quiet', '--type=gettext/ini', filepath]) gtxt_type = 'gettext/ini'
to_translate.append(filepath + '.h')
elif filename.endswith('.ui'): elif filename.endswith('.ui'):
call(['intltool-extract', '--quiet', '--type=gettext/glade', filepath]) gtxt_type = 'gettext/glade'
to_translate.append(filepath + '.h') else:
continue
call(['intltool-extract', '--quiet', '--type=%s' % gtxt_type, filepath])
filepath += '.h'
to_translate.append(filepath)
with open(INFILES_LIST, 'w') as f: with open(INFILES_LIST, 'w') as f:
for line in to_translate: for line in to_translate:

View File

@ -182,20 +182,19 @@ class BuildTranslations(cmd.Command):
basedir = os.path.join(self.build_lib, 'deluge', 'i18n') basedir = os.path.join(self.build_lib, 'deluge', 'i18n')
if not windows_check(): if not windows_check():
# creates the translated desktop file
intltool_merge = 'intltool-merge' intltool_merge = 'intltool-merge'
intltool_merge_opts = '--utf8 --quiet --desktop-style' intltool_merge_opts = '--utf8 --quiet'
desktop_in = 'deluge/ui/data/share/applications/deluge.desktop.in' for data_file in (desktop_data, appdata_data):
print('Creating desktop file: %s' % desktop_data) # creates the translated file from .in file.
os.system('C_ALL=C ' + '%s ' * 5 % (intltool_merge, intltool_merge_opts, in_file = data_file + '.in'
po_dir, desktop_in, desktop_data)) if 'xml' in data_file:
intltool_merge_opts += ' --xml-style'
elif 'desktop' in data_file:
intltool_merge_opts += ' --desktop-style'
# creates the translated appdata.xml file print('Creating file: %s' % data_file)
intltool_merge_opts = '--utf8 --quiet --xml-style' os.system('C_ALL=C ' + '%s ' * 5 % (
appdata_in = 'deluge/ui/data/share/appdata/deluge.appdata.xml.in' intltool_merge, intltool_merge_opts, po_dir, in_file, data_file))
print('Creating appdata.xml file: %s' % appdata_data)
os.system('C_ALL=C ' + '%s ' * 5 % (intltool_merge, intltool_merge_opts,
po_dir, appdata_in, appdata_data))
print('Compiling po files from %s...' % po_dir) print('Compiling po files from %s...' % po_dir)
for path, names, filenames in os.walk(po_dir): for path, names, filenames in os.walk(po_dir):
@ -239,12 +238,10 @@ class CleanTranslations(cmd.Command):
self.set_undefined_options('clean', ('all', 'all')) self.set_undefined_options('clean', ('all', 'all'))
def run(self): def run(self):
if os.path.isfile(desktop_data): for path in (desktop_data, appdata_data):
print('Deleting %s' % desktop_data) if os.path.isfile(path):
os.remove(desktop_data) print('Deleting %s' % path)
if os.path.isfile(appdata_data): os.remove(path)
print('Deleting %s' % appdata_data)
os.remove(appdata_data)
class BuildPlugins(cmd.Command): class BuildPlugins(cmd.Command):