2013-05-02 15:26:36 +00:00
|
|
|
#!/usr/bin/env python
|
2014-09-22 21:15:33 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-05-02 15:26:36 +00:00
|
|
|
#
|
2014-09-22 21:15:33 +00:00
|
|
|
# Copyright (C) 2011-2013 Calum Lind <calumlind@gmail.com>
|
|
|
|
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
2013-05-02 15:26:36 +00:00
|
|
|
#
|
2014-09-22 21:15:33 +00:00
|
|
|
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
|
|
|
# the additional special exception to link portions of this program with the OpenSSL library.
|
|
|
|
# See LICENSE for more details.
|
|
|
|
#
|
|
|
|
|
|
|
|
"""Parses Python and Javascript code for translation strings to create the 'deluge.pot' template for translators"""
|
|
|
|
|
2015-10-23 23:58:14 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2013-05-02 15:26:36 +00:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
from datetime import datetime
|
2014-09-03 23:27:11 +00:00
|
|
|
from subprocess import call
|
|
|
|
|
2015-08-22 12:04:37 +00:00
|
|
|
from gen_web_gettext import create_gettext_js
|
2014-09-03 23:27:11 +00:00
|
|
|
from version import get_version
|
2013-05-02 15:26:36 +00:00
|
|
|
|
|
|
|
# Paths to exclude
|
|
|
|
EXCLUSIONS = [
|
|
|
|
"deluge/scripts",
|
|
|
|
"deluge/i18n",
|
|
|
|
"deluge/tests",
|
|
|
|
]
|
2015-08-20 17:51:09 +00:00
|
|
|
WEBUI_JS_DIR = "deluge/ui/web/js/deluge-all"
|
|
|
|
WEBUI_RENDER_DIR = "deluge/ui/web/render"
|
|
|
|
INFILES_LIST = "infiles.list"
|
|
|
|
POT_FILEPATH = os.path.join("deluge", "i18n", "deluge.pot")
|
2013-05-02 15:26:36 +00:00
|
|
|
|
2015-10-23 23:58:14 +00:00
|
|
|
RE_EXC_PLUGIN_BUILD = re.compile("deluge\\/plugins\\/.*\\/build")
|
2013-05-02 15:26:36 +00:00
|
|
|
|
|
|
|
xgettext_cmd = [
|
|
|
|
"xgettext",
|
|
|
|
"--from-code=UTF-8",
|
|
|
|
"-kN_:1",
|
2015-08-20 17:51:09 +00:00
|
|
|
"-f%s" % INFILES_LIST,
|
|
|
|
"-o%s" % POT_FILEPATH,
|
2013-05-02 15:26:36 +00:00
|
|
|
"--package-name=%s" % "Deluge",
|
|
|
|
"--copyright-holder=%s" % "Deluge Team",
|
|
|
|
"--package-version=%s" % get_version(prefix='deluge-', suffix='.dev0'),
|
|
|
|
"--msgid-bugs-address=%s" % "http://deluge-torrent.org",
|
|
|
|
]
|
|
|
|
|
|
|
|
to_translate = []
|
|
|
|
for (dirpath, dirnames, filenames) in os.walk("deluge"):
|
|
|
|
for filename in filenames:
|
2015-08-20 17:51:09 +00:00
|
|
|
if dirpath not in EXCLUSIONS and not RE_EXC_PLUGIN_BUILD.match(dirpath):
|
2013-05-02 15:26:36 +00:00
|
|
|
filepath = os.path.join(dirpath, filename)
|
|
|
|
if os.path.splitext(filepath)[1] in (".py", ".glade"):
|
|
|
|
to_translate.append(filepath)
|
|
|
|
elif filename.endswith(".in"):
|
|
|
|
call(["intltool-extract", "--quiet", "--type=gettext/ini", filepath])
|
|
|
|
to_translate.append(filepath + ".h")
|
|
|
|
elif filename.endswith(".ui"):
|
|
|
|
call(["intltool-extract", "--quiet", "--type=gettext/glade", filepath])
|
|
|
|
to_translate.append(filepath + ".h")
|
|
|
|
|
2015-08-25 12:20:14 +00:00
|
|
|
with open(INFILES_LIST, "w") as f:
|
2013-05-02 15:26:36 +00:00
|
|
|
for line in to_translate:
|
|
|
|
f.write(line + "\n")
|
|
|
|
|
|
|
|
# Create pot file from file list
|
|
|
|
call(xgettext_cmd)
|
|
|
|
|
|
|
|
# find javascript files
|
2014-09-03 21:28:28 +00:00
|
|
|
js_to_translate = []
|
2015-08-20 17:51:09 +00:00
|
|
|
for (dirpath, dirnames, filenames) in os.walk(WEBUI_JS_DIR):
|
2013-05-02 15:26:36 +00:00
|
|
|
for filename in filenames:
|
|
|
|
if os.path.splitext(filename)[1] == ".js":
|
|
|
|
js_to_translate.append(os.path.join(dirpath, filename))
|
|
|
|
|
2015-08-20 17:51:09 +00:00
|
|
|
# find render html files
|
|
|
|
for (dirpath, dirnames, filenames) in os.walk(WEBUI_RENDER_DIR):
|
|
|
|
for filename in filenames:
|
|
|
|
if os.path.splitext(filename)[1] == ".html":
|
|
|
|
js_to_translate.append(os.path.join(dirpath, filename))
|
|
|
|
|
2015-08-25 12:20:14 +00:00
|
|
|
with open(INFILES_LIST, "w") as f:
|
2013-05-02 15:26:36 +00:00
|
|
|
for line in js_to_translate:
|
|
|
|
f.write(line + "\n")
|
|
|
|
|
|
|
|
# Force xgettext language to parse javascript and update pot file
|
2015-08-09 15:29:03 +00:00
|
|
|
# Note: For javascript files xgettext will parse comments, so single apostrophes or quotes are
|
|
|
|
# flagged as a 'warning: untermined string'. Either ignore warning or edit javascript comment.
|
2015-08-20 17:51:09 +00:00
|
|
|
call(xgettext_cmd + ["--language=Python", "-j"])
|
2013-05-02 15:26:36 +00:00
|
|
|
|
|
|
|
# Replace YEAR and PACKAGE in the copyright message
|
2015-08-20 17:51:09 +00:00
|
|
|
with open(POT_FILEPATH, "r") as f:
|
2013-05-02 15:26:36 +00:00
|
|
|
lines = f.readlines()
|
2015-08-20 17:51:09 +00:00
|
|
|
with open(POT_FILEPATH, "w") as f:
|
2013-05-02 15:26:36 +00:00
|
|
|
for line in lines:
|
|
|
|
if "YEAR" in line:
|
|
|
|
line = line.replace("YEAR", str(datetime.now().year))
|
|
|
|
elif "PACKAGE" in line:
|
|
|
|
line = line.replace("PACKAGE", "Deluge")
|
|
|
|
f.write(line)
|
|
|
|
|
|
|
|
# Clean up temp files
|
2015-08-20 17:51:09 +00:00
|
|
|
os.remove(INFILES_LIST)
|
2013-05-02 15:26:36 +00:00
|
|
|
for filepath in to_translate:
|
|
|
|
if filepath.endswith(".h"):
|
|
|
|
os.remove(filepath)
|
|
|
|
|
2015-08-22 12:04:37 +00:00
|
|
|
# Update web js gettext
|
|
|
|
create_gettext_js(WEBUI_JS_DIR)
|
|
|
|
|
2015-08-25 12:20:14 +00:00
|
|
|
print("Created %s and updated gettext.js" % POT_FILEPATH)
|