Merge lp:~dholbach/help-app/1430735-2 into lp:~ubuntu-touch-coreapps-drivers/help-app/trunk

Proposed by Daniel Holbach
Status: Merged
Merged at revision: 99
Proposed branch: lp:~dholbach/help-app/1430735-2
Merge into: lp:~ubuntu-touch-coreapps-drivers/help-app/trunk
Prerequisite: lp:~dholbach/help-app/1430735-pt1
Diff against target: 82 lines (+38/-1)
1 file modified
edit-here/translations.py (+38/-1)
To merge this branch: bzr merge lp:~dholbach/help-app/1430735-2
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Approve
Review via email: mp+253165@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'edit-here/translations.py'
2--- edit-here/translations.py 2015-03-17 09:16:29 +0000
3+++ edit-here/translations.py 2015-03-17 09:16:29 +0000
4@@ -29,7 +29,7 @@
5 except:
6 require('python3-markdown')
7
8-from pelicanconf import PATH, MD_EXTENSIONS, META_TAGS
9+from pelicanconf import PATH, MD_EXTENSIONS, META_TAGS, HIDE_FROM_POT
10
11 # This defines how complete we expect translations to be before we
12 # generate HTML from them. Needs to be string.
13@@ -149,6 +149,39 @@
14 results += [entry]
15 return results
16
17+ def hide_attr_list_statements(self):
18+ entries = []
19+ for statement in HIDE_FROM_POT:
20+ entries.extend(self.find_in_msgid(statement))
21+ statements = r'|'.join(HIDE_FROM_POT)
22+ for entry in entries:
23+ matches = re.findall(r'(.*?)\s*?(%s)\s*?' % statements,
24+ entry.msgid)
25+ # [('How do I update my system?', '!!T')]
26+ if len(matches) == 1 and len(matches[0]) == 2:
27+ entry.msgid = matches[0][0]
28+ entry.comment = matches[0][1]
29+ if matches[0][1] in entry.msgstr:
30+ entry.msgstr = entry.msgstr.replace(' %s' % matches[0][1], '')
31+ self.save()
32+
33+ def readd_attr_list_statements(self):
34+ entries = []
35+ for entry_group in [self.pofile.translated_entries(),
36+ self.pofile.fuzzy_entries(),
37+ self.pofile.untranslated_entries()]:
38+ for entry in entry_group:
39+ for statement in HIDE_FROM_POT:
40+ if statement in entry.comment:
41+ entries += [entry]
42+ for entry in entries:
43+ if not entry.msgid.endswith(entry.comment):
44+ entry.msgid += ' %s' % entry.comment
45+ if entry.msgstr and not entry.msgstr.endswith(entry.comment):
46+ entry.msgstr += ' %s' % entry.comment
47+ entry.comment = ''
48+ self.save()
49+
50 def safeguard_meta_tags(self):
51 for tag in META_TAGS:
52 for entry in self.find_in_msgid(tag):
53@@ -248,11 +281,13 @@
54 return False
55 if not self.pot_file_ob.replace_title_lines():
56 return False
57+ self.pot_file_ob.hide_attr_list_statements()
58 for po_fn in self.langs:
59 self.load_pofile(po_fn)
60 self.langs[po_fn]['pofile'].merge(self.pot_file_ob.pofile)
61 if not self.langs[po_fn]['pofile'].replace_title_lines():
62 return False
63+ self.langs[po_fn]['pofile'].hide_attr_list_statements()
64 return True
65
66 # we generate a fake translation for en-US which is going to be
67@@ -306,6 +341,7 @@
68
69 def write_translated_markdown(self, po, po4a):
70 for po_fn in po.langs:
71+ po.langs[po_fn]['pofile'].readd_attr_list_statements()
72 for doc_fn in self.docs:
73 output = self._call_po4a_translate(doc_fn, po_fn, po4a)
74 title_line = output.split('\n')[0].split('Title: ')[1]
75@@ -322,6 +358,7 @@
76 os.makedirs(os.path.dirname(new_path))
77 with open(new_path, 'w', encoding='utf-8') as f:
78 f.write(text)
79+ po.langs[po_fn]['pofile'].hide_attr_list_statements()
80
81
82 class Translations(object):

Subscribers

People subscribed via source and target branches