[damned-lies] Added support for pure gettext-based modules
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Added support for pure gettext-based modules
- Date: Thu, 1 Oct 2015 19:15:31 +0000 (UTC)
commit 7560ef30727a2061b3fc60cbd0166752da550da7
Author: Claude Paroz <claude 2xlibre net>
Date: Thu Oct 1 11:18:17 2015 +0200
Added support for pure gettext-based modules
intltool has been dropped in some modules, bug #755466.
stats/models.py | 21 ++++++++++++++++++++-
stats/utils.py | 14 +++++++-------
2 files changed, 27 insertions(+), 8 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index fb2b57a..608146b 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -701,7 +701,8 @@ class Domain(models.Model):
# The pot_method is a command who should produce a potfile in the po directory of
# the domain, named <potbase()>.pot (e.g. /po/gnucash.pot).
pot_method = models.CharField(max_length=100, null=True, blank=True,
- help_text="Leave blank for standard method (intltool for UI and gnome-doc-utils for DOC)")
+ help_text="Leave blank for standard method (intltool for UI and gnome-doc-utils for DOC), "
+ "or '<gettext>' for the pure xgettext-based extraction")
linguas_location = models.CharField(max_length=50, null=True, blank=True,
help_text="""Use 'no' for no LINGUAS check, or path/to/file#variable for a non-standard location.
Leave blank for standard location (ALL_LINGUAS in LINGUAS/configure.ac/.in for UI and
DOC_LINGUAS in Makefile.am for DOC)""")
@@ -716,6 +717,10 @@ class Domain(models.Model):
return "%s (%s/%s)" % (self.name, self.module.name, self.get_dtype_display())
def potbase(self):
+ """
+ Return the name of the generated pot file, without extension.
+ (--default-domain for xgettext, --gettext-package for intltool)
+ """
if self.name[:2] == 'po':
# e.g. replace po by gimp (for ui), or po-plugins by gimp-plugins
return self.module.name + self.name[2:]
@@ -765,6 +770,20 @@ class Domain(models.Model):
podir = vcs_path
if not self.pot_method: # default is intltool
pot_command = ['intltool-update', '-g', self.potbase(), '-p']
+ elif self.pot_method == '<gettext>':
+ pot_command = ['xgettext',
+ '--files-from', 'POTFILES.in',
+ '--directory', current_branch.co_path(),
+ '--from-code', 'utf-8',
+ '--add-comments',
+ '--output', '%s.pot' % self.potbase(),
+ ]
+ # Parse and use content from: "XGETTEXT_OPTIONS = --keyword=_ --keyword=N_"
+ kwds_vars = utils.read_makefile_variable([vcs_path], 'XGETTEXT_OPTIONS',
makefile_name='Makevars')
+ if kwds_vars:
+ pot_command.extend(kwds_vars.split())
+ # Added last as some chars in it may disturb CLI parsing
+ pot_command.extend(['--msgid-bugs-address', self.module.get_bugs_enter_url()])
elif self.pot_method.startswith(('http://', 'https://')):
# Get POT from URL and save file locally
import urllib2
diff --git a/stats/utils.py b/stats/utils.py
index c5d3022..66b4128 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -260,18 +260,18 @@ def generate_doc_pot_file(vcs_path, potbase, moduleid):
else:
return potfile, errors, doc_format
-def read_makefile_variable(vcs_paths, variable, default=None):
+
+def read_makefile_variable(vcs_paths, variable, makefile_name='Makefile.am', default=None):
""" vcs_paths is a list of potential path where Makefile.am could be found """
- makefiles = [os.path.join(path, "Makefile.am") for path in vcs_paths]
- good_makefile = None
+ makefiles = [os.path.join(path, makefile_name) for path in vcs_paths]
for makefile in makefiles:
if os.access(makefile, os.R_OK):
- good_makefile = makefile
break
- if not good_makefile:
+ else:
return default # no file found
- return search_variable_in_file(good_makefile, variable)
+ return search_variable_in_file(makefile, variable)
+
def search_variable_in_file(file_path, variable):
""" Search for a variable value in a file, and return content if found
@@ -297,7 +297,7 @@ def search_variable_in_file(file_path, variable):
else:
non_terminated_content = ""
# Search for variable
- match = re.search('%s\s*[=,]\s*"?([^"=]*)"?' % variable, line)
+ match = re.search('%s\s*[=,]\s*"?([^"]*)"?' % variable, line)
if match:
found = match.group(1)
break
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]