2018-12-29 19:14:41 +00:00
|
|
|
#! /usr/bin/python3
|
2007-09-07 16:37:38 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Copyright (C) 2007 Michael Gerz <michael.gerz@teststep.org>
|
|
|
|
# Copyright (C) 2007 José Matos <jamatos@lyx.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
"""
|
|
|
|
This script extracts some information from the po file headers (last
|
|
|
|
translator, revision date), generates the corresponding gmo files
|
|
|
|
to retrieve the number of translated/fuzzy/untranslated messages,
|
|
|
|
and generates a PHP web page.
|
|
|
|
|
|
|
|
Invocation:
|
2008-01-04 17:01:08 +00:00
|
|
|
postats.py lyx_version po_files > "pathToWebPages"/i18n.inc
|
2024-09-06 21:06:52 +00:00
|
|
|
|
|
|
|
or simply
|
|
|
|
make i18n.inc
|
|
|
|
to create stats only for allowed langauages in LINGUAS file
|
|
|
|
(typically good for stable branch stats).
|
2007-09-07 16:37:38 +00:00
|
|
|
"""
|
2015-03-11 13:41:10 +00:00
|
|
|
from __future__ import print_function
|
2007-09-07 16:37:38 +00:00
|
|
|
|
2022-11-23 22:29:11 +00:00
|
|
|
# Modify this when you change branch (e.g. stats for stable branch).
|
|
|
|
# Note that an empty lyx_branch variable will "do the right thing" for master.
|
2007-09-07 16:37:38 +00:00
|
|
|
lyx_branch=""
|
2008-12-07 10:55:03 +00:00
|
|
|
# these po-files will be skipped:
|
|
|
|
ommitted = ('en.po')
|
2007-09-07 16:37:38 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2019-07-15 16:07:22 +00:00
|
|
|
import codecs
|
2019-07-15 21:32:22 +00:00
|
|
|
import subprocess
|
2019-07-15 16:07:22 +00:00
|
|
|
from subprocess import Popen, PIPE
|
2007-09-07 16:37:38 +00:00
|
|
|
|
2007-10-15 08:57:42 +00:00
|
|
|
# Reset the locale
|
|
|
|
import locale
|
2018-12-29 19:14:41 +00:00
|
|
|
locale.setlocale(locale.LC_ALL, 'C')
|
2008-02-20 16:31:50 +00:00
|
|
|
os.environ['LC_ALL'] = 'C'
|
2007-10-15 08:57:42 +00:00
|
|
|
|
2007-09-07 16:37:38 +00:00
|
|
|
def extract_number(line, issues, prop):
|
|
|
|
"""
|
|
|
|
line is a string like
|
|
|
|
'588 translated messages, 1248 fuzzy translations, 2 untranslated messages.'
|
|
|
|
Any one of these substrings may not appear if the associated number is 0.
|
|
|
|
|
|
|
|
issues is the set of words following the number to be extracted,
|
|
|
|
ie, 'translated', 'fuzzy', or 'untranslated'.
|
|
|
|
|
|
|
|
extract_number returns a list with those numbers, or sets it to
|
|
|
|
zero if the word is not found in the string.
|
|
|
|
"""
|
|
|
|
|
|
|
|
for issue in issues:
|
|
|
|
i = line.find(issue)
|
|
|
|
|
|
|
|
if i == -1:
|
|
|
|
prop[issue] = 0
|
|
|
|
else:
|
|
|
|
prop[issue] = int(line[:i].split()[-1])
|
|
|
|
|
|
|
|
|
|
|
|
def read_pofile(pofile):
|
|
|
|
""" Read the header of the pofile and return it as a dictionary"""
|
|
|
|
header = {}
|
|
|
|
read_header = False
|
2019-07-15 16:07:22 +00:00
|
|
|
for line in codecs.open(pofile, encoding='utf8'):
|
2007-09-07 16:37:38 +00:00
|
|
|
line = line[:-1]
|
|
|
|
if line[:5] == 'msgid':
|
|
|
|
if read_header:
|
|
|
|
break
|
|
|
|
read_header = True
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not line or line[0] == '#' or line == 'msgstr ""' or not read_header:
|
|
|
|
continue
|
|
|
|
|
|
|
|
line = line.strip('"')
|
|
|
|
args = line.split(': ')
|
|
|
|
if len(args) == 1:
|
|
|
|
continue
|
|
|
|
header[args[0]] = args[1].strip()[:-2]
|
|
|
|
|
|
|
|
return header
|
|
|
|
|
|
|
|
|
|
|
|
def run_msgfmt(pofile):
|
|
|
|
""" pofile is the name of the po file.
|
|
|
|
The function runs msgfmt on it and returns corresponding php code.
|
|
|
|
"""
|
|
|
|
if not pofile.endswith('.po'):
|
2015-03-11 13:41:10 +00:00
|
|
|
print("%s is not a po file" % pofile, file=sys.stderr)
|
2007-09-07 16:37:38 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
dirname = os.path.dirname(pofile)
|
|
|
|
gmofile = pofile.replace('.po', '.gmo')
|
|
|
|
|
|
|
|
header = read_pofile(pofile)
|
|
|
|
charset= header['Content-Type'].split('charset=')[1]
|
|
|
|
|
|
|
|
# po file properties
|
|
|
|
prop = {}
|
|
|
|
prop["langcode"] = os.path.basename(pofile)[:-3]
|
|
|
|
prop["date"] = header['PO-Revision-Date'].split()[0]
|
|
|
|
prop["email"] = header['Last-Translator'].split('<')[1][:-1]
|
2007-10-23 08:23:39 +00:00
|
|
|
prop["email"] = prop["email"].replace("@", " () ")
|
|
|
|
prop["email"] = prop["email"].replace(".", " ! ")
|
2019-07-15 21:32:22 +00:00
|
|
|
prop["translator"] = header['Last-Translator'].split('<')[0].strip()
|
|
|
|
|
|
|
|
msg = subprocess.check_output(["msgfmt", "--statistics",
|
|
|
|
"-o", gmofile, # FIXME: do we really want a gmofile as side-effect?
|
|
|
|
pofile], stderr=subprocess.STDOUT)
|
|
|
|
if sys.version_info[0] > 2:
|
|
|
|
msg = msg.decode('utf8')
|
|
|
|
extract_number(msg, ('translated', 'fuzzy', 'untranslated'), prop)
|
2007-09-07 16:37:38 +00:00
|
|
|
return """
|
|
|
|
array ( 'langcode' => '%(langcode)s', "date" => "%(date)s",
|
|
|
|
"msg_tr" => %(translated)d, "msg_fu" => %(fuzzy)d, "msg_nt" => %(untranslated)d,
|
|
|
|
"translator" => "%(translator)s", "email" => "%(email)s")""" % prop
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if lyx_branch:
|
2013-05-30 18:09:26 +00:00
|
|
|
branch_tag = lyx_branch
|
2007-09-07 16:37:38 +00:00
|
|
|
else:
|
2013-05-30 18:09:26 +00:00
|
|
|
branch_tag = "master"
|
2007-09-07 16:37:38 +00:00
|
|
|
|
|
|
|
|
2015-03-11 13:41:10 +00:00
|
|
|
print("""<?php
|
2007-09-07 16:37:38 +00:00
|
|
|
// The current version
|
2007-09-21 13:52:52 +00:00
|
|
|
$lyx_version = "%s";
|
2024-08-22 21:00:50 +00:00
|
|
|
// The branch tag which will be used for git URL pointing to proper .po file
|
2007-09-21 13:52:52 +00:00
|
|
|
$branch_tag = "%s";
|
2007-09-07 16:37:38 +00:00
|
|
|
|
|
|
|
// The data itself
|
2007-09-21 13:52:52 +00:00
|
|
|
$podata = array (%s
|
2019-07-15 21:32:22 +00:00
|
|
|
)?>""" % (sys.argv[1], branch_tag,
|
|
|
|
",".join([run_msgfmt(po) for po in sys.argv[2:]
|
|
|
|
if po not in ommitted])))
|