492.1.3
by Iain Lane
Add a script which extracts the name and keywords from .settings files for translation. |
1 |
#!/usr/bin/python
|
2 |
#
|
|
3 |
# This file is part of system-settings
|
|
4 |
#
|
|
5 |
# Copyright (C) 2013 Canonical Ltd.
|
|
6 |
#
|
|
7 |
# Contact: Iain Lane <iain.lane@canonical.com>
|
|
8 |
#
|
|
9 |
# This program is free software: you can redistribute it and/or modify it
|
|
10 |
# under the terms of the GNU General Public License version 3, as published
|
|
11 |
# by the Free Software Foundation.
|
|
12 |
#
|
|
13 |
# This program is distributed in the hope that it will be useful, but
|
|
14 |
# WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
15 |
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
16 |
# PURPOSE. See the GNU General Public License for more details.
|
|
17 |
#
|
|
18 |
# You should have received a copy of the GNU General Public License along
|
|
19 |
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 |
||
21 |
# Output the name and keywords from .settings files specified on the
|
|
22 |
# commandline in a format that can be parsed by xgettext
|
|
23 |
||
24 |
from __future__ import print_function |
|
25 |
||
26 |
import argparse |
|
27 |
import json |
|
28 |
import os |
|
29 |
||
30 |
def output(text, name, write): |
|
31 |
print ("// TRANSLATORS: This is a keyword or name for the %s plugin which " |
|
32 |
"is used while searching" % |
|
33 |
os.path.splitext(os.path.basename(name))[0], file=write) |
|
34 |
print('var s = i18n.tr(%s)' % json.dumps(text), file=write) |
|
35 |
||
36 |
def printkeywords(fh, write): |
|
37 |
parsed = json.load(fh) |
|
38 |
if "name" in parsed: |
|
39 |
output(parsed["name"], fh.name, write) |
|
40 |
if "keywords" in parsed: |
|
41 |
for k in parsed["keywords"]: |
|
42 |
output(k, fh.name, write) |
|
43 |
||
44 |
parser = argparse.ArgumentParser(description="Process settings file for" |
|
45 |
"translation") |
|
46 |
parser.add_argument("-o", "--output", type=argparse.FileType("w")) |
|
47 |
parser.add_argument("files", nargs="*", type=argparse.FileType("r")) |
|
48 |
||
49 |
args = parser.parse_args() |
|
50 |
||
51 |
text = set() |
|
52 |
||
53 |
for file in args.files: |
|
54 |
printkeywords(file, args.output) |