Rev 7991 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7156 | jlepiller | 1 | #!/usr/bin/python3 |
2 | # -*- coding: utf-8 -*- |
||
3 | |||
4 | # Template Translator v0.1 |
||
5 | # Traduit automatiquement certaines chaine de caractères des paquets |
||
6 | |||
7 | # Publié par roptat <julien@lepiller.eu> le 8 août 2016 |
||
8 | # sous la licence gnu General Public License version 3 pubilée par la Free Software Foundation. |
||
9 | # Visitez <http://www.gnu.org/licenses/> pour obtenir la licence. |
||
10 | |||
11 | |||
12 | import sys |
||
13 | import re |
||
14 | import polib |
||
15 | |||
16 | files = sys.argv |
||
17 | files.pop(0) |
||
18 | |||
19 | def convert(entry, regexp, template): |
||
20 | m = regexp.match(entry.msgid) |
||
21 | # do not modify anything if the translation is already correct |
||
22 | #if m and ("fuzzy" in entry.flags or not entry.msgstr): |
||
23 | if m: |
||
24 | msgstr = template |
||
25 | try: |
||
26 | msgstr = msgstr.replace("#1", m.group(1)) |
||
27 | msgstr = msgstr.replace('#2', m.group(2)) |
||
28 | msgstr = msgstr.replace('#3', m.group(3)) |
||
29 | msgstr = msgstr.replace('#4', m.group(4)) |
||
30 | except: |
||
31 | x=1 |
||
32 | entry.msgstr = msgstr |
||
7170 | jlepiller | 33 | if "fuzzy" in entry.flags: |
34 | entry.flags.remove("fuzzy") |
||
7156 | jlepiller | 35 | |
36 | |||
37 | frenchMonth = { |
||
7225 | jlepiller | 38 | 'January': 'janvier', |
39 | 'February': 'février', |
||
40 | 'March': 'mars', |
||
41 | 'April': 'avril', |
||
42 | 'May': 'mai', |
||
43 | 'June': 'juin', |
||
44 | 'July': 'juillet', |
||
45 | 'August': 'août', |
||
46 | 'September': 'septembre', |
||
47 | 'October': 'octobre', |
||
48 | 'November': 'novembre', |
||
49 | 'December': 'décembre' |
||
7156 | jlepiller | 50 | } |
51 | |||
52 | # regexps |
||
53 | regexps = [] |
||
54 | |||
8230 | jlepiller | 55 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+).?$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2.']) |
56 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2. Corrige #3']) |
||
57 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? ([^ ]+). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2. Corrige #3']) |
||
58 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+). +Part of (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] – Mise à jour vers #2. Corrige partiellement #3']) |
||
59 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+) and ([^ ]+). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2 et #3. Corrige #4']) |
||
60 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+) ([0-9\.]+). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2 #3. Corrige #4']) |
||
61 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+). +Partially fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2. Corrige partiellement #3']) |
||
62 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+) (\([^ ]+\)). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2 #3. Corrige #4']) |
||
63 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+) \(([^ ]+) [mM]odule\). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2 (module #3). Corrige #4']) |
||
64 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+) \([sS]ecurity [fF]ixe?s?\). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2 (correctif de sécurité). Corrige #3']) |
||
65 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+) \([sS]ecurity [uU]pdate?s?\). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2 (correctif de sécurité). Corrige #3']) |
||
66 | regexps.append([re.compile('\[([^\]]+)\] - Up[dg]r?a[td]ed? to ([^ ]+) \(Xorg Library\). +Fixes (<ulink [^>]+> *#[0-9]+ *</ulink>.?)$', re.MULTILINE|re.DOTALL), '[#1] — Mise à jour vers #2 (bibliothèque Xorg). Corrige #3']) |
||
67 | regexps.append([re.compile('\[([^\]]+)\] - Reintroduce ([^ ]+).?$', re.MULTILINE|re.DOTALL), '[#1] — Réintroduction de #2.']) |
||
68 | regexps.append([re.compile('\[([^\]]+)\] - Reinstate ([^ ]+).?$', re.MULTILINE|re.DOTALL), '[#1] — Réintroduction de #2.']) |
||
69 | regexps.append([re.compile('\[([^\]]+)\] - Add? ([^ ]+).?$', re.MULTILINE|re.DOTALL), '[#1] — Ajout de #2.']) |
||
7156 | jlepiller | 70 | |
7425 | jlepiller | 71 | datereg = re.compile('([^ ]+) ([0-9]{1,2})(th|nd|st|rd|),? (20[0-9]{2})') |
7156 | jlepiller | 72 | |
73 | |||
74 | |||
75 | #regexps.append([re.compile('$'), '']) |
||
76 | |||
77 | number = len(files) |
||
78 | current = 1 |
||
79 | |||
80 | for filename in files: |
||
81 | print('Traitement du fichier ', current, '/', number, ' \r', |
||
82 | end="", flush=True), |
||
83 | current = current + 1 |
||
84 | po = polib.pofile(filename) |
||
85 | for entry in po: |
||
86 | for reg in regexps: |
||
87 | convert(entry, reg[0], reg[1]) |
||
88 | m = datereg.match(entry.msgid) |
||
89 | if m and ("fuzzy" in entry.flags or not entry.msgstr): |
||
90 | day = m.group(2) |
||
91 | if int(day) == 1: |
||
92 | day = '1er' |
||
7226 | jlepiller | 93 | try: |
94 | month = frenchMonth[m.group(1)] |
||
95 | year = m.group(4) |
||
96 | entry.msgstr = day + " " + month + " " + year |
||
97 | if "fuzzy" in entry.flags: |
||
98 | entry.flags.remove("fuzzy") |
||
99 | except: |
||
100 | pass |
||
7156 | jlepiller | 101 | po.save() |
102 | print('') |
||
103 |