author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Fri, 12 Feb 2021 21:58:03 +0100 | |
branch | svghmi |
changeset 3135 | d723472a18a4 |
parent 3133 | 450cd01324ad |
child 3144 | 2af6afaccaf2 |
permissions | -rw-r--r-- |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
1 |
#!/usr/bin/env python |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
3 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
4 |
# This file is part of Beremiz |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
5 |
# Copyright (C) 2021: Edouard TISSERANT |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
6 |
# |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
7 |
# See COPYING file for copyrights details. |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
8 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
9 |
from __future__ import absolute_import |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
10 |
from lxml import etree |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
11 |
import os |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
12 |
import sys |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
13 |
import subprocess |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
14 |
import time |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
15 |
import ast |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
16 |
import wx |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
17 |
|
3133
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
18 |
# to have it for python 2, had to install |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
19 |
# https://pypi.org/project/pycountry/18.12.8/ |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
20 |
# python2 -m pip install pycountry==18.12.8 --user |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
21 |
import pycountry |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
22 |
|
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
23 |
def open_pofile(pofile): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
24 |
""" Opens PO file with POEdit """ |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
25 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
26 |
if sys.platform.startswith('win'): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
27 |
from six.moves import winreg |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
28 |
poedit_cmd = None |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
29 |
try: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
30 |
poedit_cmd = winreg.QueryValue(winreg.HKEY_LOCAL_MACHINE, |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
31 |
'SOFTWARE\\Classes\\poedit\\shell\\open\\command') |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
32 |
poedit_path = poedit_cmd.replace('"%1"', '').strip().replace('"', '') |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
33 |
except OSError: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
34 |
poedit_path = None |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
35 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
36 |
else: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
37 |
try: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
38 |
poedit_path = subprocess.check_output("command -v poedit", shell=True).strip() |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
39 |
except subprocess.CalledProcessError: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
40 |
poedit_path = None |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
41 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
42 |
if poedit_path is None: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
43 |
wx.MessageBox("POEdit is not found or installed !") |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
44 |
else: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
45 |
subprocess.Popen([poedit_path,pofile]) |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
46 |
|
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
47 |
def EtreeToMessages(msgs): |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
48 |
""" Converts XML tree from 'extract_i18n' templates into a list of tuples """ |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
49 |
messages = [] |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
50 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
51 |
for msg in msgs: |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
52 |
messages.append(( |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
53 |
"\n".join([line.text for line in msg]), |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
54 |
msg.get("label"), msg.get("id"))) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
55 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
56 |
return messages |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
57 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
58 |
def SaveCatalog(fname, messages): |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
59 |
""" Save messages given as list of tupple (msg,label,id) in POT file """ |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
60 |
w = POTWriter() |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
61 |
w.ImportMessages(messages) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
62 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
63 |
with open(fname, 'w') as POT_file: |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
64 |
w.write(POT_file) |
3114
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
65 |
|
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
66 |
def ReadTranslations(dirpath): |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
67 |
""" Read all PO files from a directory and return a list of (lang, translation_dict) tuples """ |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
68 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
69 |
po_files = [fname for fname in os.listdir(dirpath) if fname.endswith(".po")] |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
70 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
71 |
translations = [] |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
72 |
for po_fname in po_files: |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
73 |
r = POReader() |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
74 |
with open(os.path.join(dirpath, po_fname), 'r') as PO_file: |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
75 |
r.read(PO_file) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
76 |
translations.append((po_fname[:-3], r.get_messages())) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
77 |
return translations |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
78 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
79 |
def MatchTranslations(translations, messages, errcallback): |
3114
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
80 |
""" |
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
81 |
Matches translations against original message catalog, |
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
82 |
warn about inconsistancies, |
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
83 |
returns list of langs, and a list of (msgid, [translations]) tuples |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
84 |
""" |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
85 |
translated_messages = [] |
3114
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
86 |
broken_lang = set() |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
87 |
for msgid,label,svgid in messages: |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
88 |
translated_message = [] |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
89 |
for lang,translation in translations: |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
90 |
msg = translation.pop(msgid, None) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
91 |
if msg is None: |
3114
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
92 |
broken_lang.add(lang) |
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
93 |
errcallback(_('{}: Missing translation for "{}" (label:{}, id:{})\n').format(lang,msgid,label,svgid)) |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
94 |
translated_message.append(msgid) |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
95 |
else: |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
96 |
translated_message.append(msg) |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
97 |
translated_messages.append((msgid,translated_message)) |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
98 |
langs = [] |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
99 |
for lang,translation in translations: |
3133
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
100 |
try: |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
101 |
l,c = lang.split("_") |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
102 |
language_name = pycountry.languages.get(alpha_2 = l).name |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
103 |
country_name = pycountry.countries.get(alpha_2 = c).name |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
104 |
langs.append("{} ({})".format(language_name, country_name)) |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
105 |
except: |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
106 |
try: |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
107 |
language_name = pycountry.languages.get(alpha_2 = lang).name |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
108 |
langs.append(language_name) |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
109 |
except: |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
110 |
langs.append(lang) |
450cd01324ad
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3116
diff
changeset
|
111 |
|
3114
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
112 |
broken = False |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
113 |
for msgid, msg in translation.iteritems(): |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
114 |
broken = True |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
115 |
errcallback(_('{}: Unused translation "{}":"{}"\n').format(lang,msgid,msg)) |
3114
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
116 |
if broken or lang in broken_lang: |
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
117 |
errcallback(_('Translation for {} is outdated, please edit {}.po, click "Catalog -> Update from POT File..." and select messages.pot.\n').format(lang,lang)) |
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
118 |
|
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
119 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
120 |
return langs,translated_messages |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
121 |
|
3114
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
122 |
|
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
123 |
def TranslationToEtree(langs,translated_messages): |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
124 |
|
3116
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
125 |
result = etree.Element("translations") |
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
126 |
|
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
127 |
langsroot = etree.SubElement(result, "langs") |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
128 |
for lang in langs: |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
129 |
langel = etree.SubElement(langsroot, "lang") |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
130 |
langel.text = lang |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
131 |
|
3116
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
132 |
msgsroot = etree.SubElement(result, "messages") |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
133 |
for msgid, msgs in translated_messages: |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
134 |
msgidel = etree.SubElement(msgsroot, "msgid") |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
135 |
for msg in msgs: |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
136 |
msgel = etree.SubElement(msgidel, "msg") |
3116
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
137 |
for line in msg.split("\n"): |
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
138 |
lineel = etree.SubElement(msgel, "line") |
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
139 |
lineel.text = escape(line.encode("utf-8")).decode("utf-8") |
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
140 |
|
6da94ec04325
SVGHMI: i18n: finished passing back translated messaged to xslt proc, finished template to generate corresponding javascript literals.
Edouard Tisserant
parents:
3115
diff
changeset
|
141 |
return result |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
142 |
|
3114
fb1e320836e8
SVGHMI: i18n: better warning messages, more explicit.
Edouard Tisserant
parents:
3113
diff
changeset
|
143 |
|
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
144 |
|
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
145 |
locpfx = '#:svghmi.svg:' |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
146 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
147 |
pot_header = '''\ |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
148 |
# SOME DESCRIPTIVE TITLE. |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
149 |
# Copyright (C) YEAR ORGANIZATION |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
150 |
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
151 |
# |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
152 |
msgid "" |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
153 |
msgstr "" |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
154 |
"Project-Id-Version: PACKAGE VERSION\\n" |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
155 |
"POT-Creation-Date: %(time)s\\n" |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
156 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n" |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
157 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n" |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
158 |
"Language-Team: LANGUAGE <LL@li.org>\\n" |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
159 |
"MIME-Version: 1.0\\n" |
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
160 |
"Content-Type: text/plain; charset=UTF-8\\n" |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
161 |
"Content-Transfer-Encoding: 8bit\\n" |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
162 |
"Generated-By: SVGHMI 1.0\\n" |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
163 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
164 |
''' |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
165 |
escapes = [] |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
166 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
167 |
def make_escapes(pass_iso8859): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
168 |
global escapes |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
169 |
escapes = [chr(i) for i in range(256)] |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
170 |
if pass_iso8859: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
171 |
# Allow iso-8859 characters to pass through so that e.g. 'msgid |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
172 |
# "Höhe"' would result not result in 'msgid "H\366he"'. Otherwise we |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
173 |
# escape any character outside the 32..126 range. |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
174 |
mod = 128 |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
175 |
else: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
176 |
mod = 256 |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
177 |
for i in range(mod): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
178 |
if not(32 <= i <= 126): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
179 |
escapes[i] = "\\%03o" % i |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
180 |
escapes[ord('\\')] = '\\\\' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
181 |
escapes[ord('\t')] = '\\t' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
182 |
escapes[ord('\r')] = '\\r' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
183 |
escapes[ord('\n')] = '\\n' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
184 |
escapes[ord('\"')] = '\\"' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
185 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
186 |
make_escapes(pass_iso8859 = True) |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
187 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
188 |
EMPTYSTRING = '' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
189 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
190 |
def escape(s): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
191 |
global escapes |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
192 |
s = list(s) |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
193 |
for i in range(len(s)): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
194 |
s[i] = escapes[ord(s[i])] |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
195 |
return EMPTYSTRING.join(s) |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
196 |
|
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
197 |
def normalize(s): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
198 |
# This converts the various Python string types into a format that is |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
199 |
# appropriate for .po files, namely much closer to C style. |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
200 |
lines = s.split('\n') |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
201 |
if len(lines) == 1: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
202 |
s = '"' + escape(s) + '"' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
203 |
else: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
204 |
if not lines[-1]: |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
205 |
del lines[-1] |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
206 |
lines[-1] = lines[-1] + '\n' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
207 |
for i in range(len(lines)): |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
208 |
lines[i] = escape(lines[i]) |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
209 |
lineterm = '\\n"\n"' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
210 |
s = '""\n"' + lineterm.join(lines) + '"' |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
211 |
return s |
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
212 |
|
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
213 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
214 |
class POTWriter: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
215 |
def __init__(self): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
216 |
self.__messages = {} |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
217 |
|
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
218 |
def ImportMessages(self, msgs): |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
219 |
for msg, label, svgid in msgs: |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
220 |
self.addentry(msg.encode("utf-8"), label, svgid) |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
221 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
222 |
def addentry(self, msg, label, svgid): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
223 |
entry = (label, svgid) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
224 |
self.__messages.setdefault(msg, set()).add(entry) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
225 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
226 |
def write(self, fp): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
227 |
timestamp = time.strftime('%Y-%m-%d %H:%M+%Z') |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
228 |
print >> fp, pot_header % {'time': timestamp} |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
229 |
reverse = {} |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
230 |
for k, v in self.__messages.items(): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
231 |
keys = list(v) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
232 |
keys.sort() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
233 |
reverse.setdefault(tuple(keys), []).append((k, v)) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
234 |
rkeys = reverse.keys() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
235 |
rkeys.sort() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
236 |
for rkey in rkeys: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
237 |
rentries = reverse[rkey] |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
238 |
rentries.sort() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
239 |
for k, v in rentries: |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
240 |
v = list(v) |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
241 |
v.sort() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
242 |
locline = locpfx |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
243 |
for label, svgid in v: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
244 |
d = {'label': label, 'svgid': svgid} |
3112
bd20f9112014
SVGHMI: still WIP, now POT file is properly generated with utf-8 encoding and POEdit is launched when pressing button.
Edouard Tisserant
parents:
3108
diff
changeset
|
245 |
s = _(' %(label)s:%(svgid)s') % d |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
246 |
if len(locline) + len(s) <= 78: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
247 |
locline = locline + s |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
248 |
else: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
249 |
print >> fp, locline |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
250 |
locline = locpfx + s |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
251 |
if len(locline) > len(locpfx): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
252 |
print >> fp, locline |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
253 |
print >> fp, 'msgid', normalize(k) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
254 |
print >> fp, 'msgstr ""\n' |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
255 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
256 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
257 |
class POReader: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
258 |
def __init__(self): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
259 |
self.__messages = {} |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
260 |
|
3113
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
261 |
def get_messages(self): |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
262 |
return self.__messages |
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
263 |
|
18133b90196e
SVGHMI: i18n: now loads PO filesand match translation against catalog. Refactored a bit to move i18n related code in i18n.py
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3112
diff
changeset
|
264 |
def add(self, msgid, msgstr, fuzzy): |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
265 |
"Add a non-fuzzy translation to the dictionary." |
3115
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
266 |
if not fuzzy and msgstr and msgid: |
77cfbf1aacf0
SVGHMI: i18n: various fixes about unicode encoding and converting translation result back to XML to feed xslt processor
Edouard Tisserant
parents:
3114
diff
changeset
|
267 |
self.__messages[msgid.decode('utf-8')] = msgstr.decode('utf-8') |
3108
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
268 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
269 |
def read(self, fp): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
270 |
ID = 1 |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
271 |
STR = 2 |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
272 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
273 |
lines = fp.readlines() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
274 |
section = None |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
275 |
fuzzy = 0 |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
276 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
277 |
# Parse the catalog |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
278 |
lno = 0 |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
279 |
for l in lines: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
280 |
lno += 1 |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
281 |
# If we get a comment line after a msgstr, this is a new entry |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
282 |
if l[0] == '#' and section == STR: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
283 |
self.add(msgid, msgstr, fuzzy) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
284 |
section = None |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
285 |
fuzzy = 0 |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
286 |
# Record a fuzzy mark |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
287 |
if l[:2] == '#,' and 'fuzzy' in l: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
288 |
fuzzy = 1 |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
289 |
# Skip comments |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
290 |
if l[0] == '#': |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
291 |
continue |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
292 |
# Now we are in a msgid section, output previous section |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
293 |
if l.startswith('msgid') and not l.startswith('msgid_plural'): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
294 |
if section == STR: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
295 |
self.add(msgid, msgstr, fuzzy) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
296 |
section = ID |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
297 |
l = l[5:] |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
298 |
msgid = msgstr = '' |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
299 |
is_plural = False |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
300 |
# This is a message with plural forms |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
301 |
elif l.startswith('msgid_plural'): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
302 |
if section != ID: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
303 |
print >> sys.stderr, 'msgid_plural not preceded by msgid on %s:%d' %\ |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
304 |
(infile, lno) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
305 |
sys.exit(1) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
306 |
l = l[12:] |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
307 |
msgid += '\0' # separator of singular and plural |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
308 |
is_plural = True |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
309 |
# Now we are in a msgstr section |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
310 |
elif l.startswith('msgstr'): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
311 |
section = STR |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
312 |
if l.startswith('msgstr['): |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
313 |
if not is_plural: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
314 |
print >> sys.stderr, 'plural without msgid_plural on %s:%d' %\ |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
315 |
(infile, lno) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
316 |
sys.exit(1) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
317 |
l = l.split(']', 1)[1] |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
318 |
if msgstr: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
319 |
msgstr += '\0' # Separator of the various plural forms |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
320 |
else: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
321 |
if is_plural: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
322 |
print >> sys.stderr, 'indexed msgstr required for plural on %s:%d' %\ |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
323 |
(infile, lno) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
324 |
sys.exit(1) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
325 |
l = l[6:] |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
326 |
# Skip empty lines |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
327 |
l = l.strip() |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
328 |
if not l: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
329 |
continue |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
330 |
l = ast.literal_eval(l) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
331 |
if section == ID: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
332 |
msgid += l |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
333 |
elif section == STR: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
334 |
msgstr += l |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
335 |
else: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
336 |
print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), \ |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
337 |
'before:' |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
338 |
print >> sys.stderr, l |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
339 |
sys.exit(1) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
340 |
# Add last entry |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
341 |
if section == STR: |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
342 |
self.add(msgid, msgstr, fuzzy) |
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
343 |
|
079419e7228d
SVGHMI: Intermediate commit while implementing i18n. WIP.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
344 |