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
=== modified file 'edit-here/translations.py'
--- edit-here/translations.py 2015-03-17 09:16:29 +0000
+++ edit-here/translations.py 2015-03-17 09:16:29 +0000
@@ -29,7 +29,7 @@
29except:29except:
30 require('python3-markdown')30 require('python3-markdown')
3131
32from pelicanconf import PATH, MD_EXTENSIONS, META_TAGS32from pelicanconf import PATH, MD_EXTENSIONS, META_TAGS, HIDE_FROM_POT
3333
34# This defines how complete we expect translations to be before we34# This defines how complete we expect translations to be before we
35# generate HTML from them. Needs to be string.35# generate HTML from them. Needs to be string.
@@ -149,6 +149,39 @@
149 results += [entry]149 results += [entry]
150 return results150 return results
151151
152 def hide_attr_list_statements(self):
153 entries = []
154 for statement in HIDE_FROM_POT:
155 entries.extend(self.find_in_msgid(statement))
156 statements = r'|'.join(HIDE_FROM_POT)
157 for entry in entries:
158 matches = re.findall(r'(.*?)\s*?(%s)\s*?' % statements,
159 entry.msgid)
160 # [('How do I update my system?', '!!T')]
161 if len(matches) == 1 and len(matches[0]) == 2:
162 entry.msgid = matches[0][0]
163 entry.comment = matches[0][1]
164 if matches[0][1] in entry.msgstr:
165 entry.msgstr = entry.msgstr.replace(' %s' % matches[0][1], '')
166 self.save()
167
168 def readd_attr_list_statements(self):
169 entries = []
170 for entry_group in [self.pofile.translated_entries(),
171 self.pofile.fuzzy_entries(),
172 self.pofile.untranslated_entries()]:
173 for entry in entry_group:
174 for statement in HIDE_FROM_POT:
175 if statement in entry.comment:
176 entries += [entry]
177 for entry in entries:
178 if not entry.msgid.endswith(entry.comment):
179 entry.msgid += ' %s' % entry.comment
180 if entry.msgstr and not entry.msgstr.endswith(entry.comment):
181 entry.msgstr += ' %s' % entry.comment
182 entry.comment = ''
183 self.save()
184
152 def safeguard_meta_tags(self):185 def safeguard_meta_tags(self):
153 for tag in META_TAGS:186 for tag in META_TAGS:
154 for entry in self.find_in_msgid(tag):187 for entry in self.find_in_msgid(tag):
@@ -248,11 +281,13 @@
248 return False281 return False
249 if not self.pot_file_ob.replace_title_lines():282 if not self.pot_file_ob.replace_title_lines():
250 return False283 return False
284 self.pot_file_ob.hide_attr_list_statements()
251 for po_fn in self.langs:285 for po_fn in self.langs:
252 self.load_pofile(po_fn)286 self.load_pofile(po_fn)
253 self.langs[po_fn]['pofile'].merge(self.pot_file_ob.pofile)287 self.langs[po_fn]['pofile'].merge(self.pot_file_ob.pofile)
254 if not self.langs[po_fn]['pofile'].replace_title_lines():288 if not self.langs[po_fn]['pofile'].replace_title_lines():
255 return False289 return False
290 self.langs[po_fn]['pofile'].hide_attr_list_statements()
256 return True291 return True
257292
258 # we generate a fake translation for en-US which is going to be293 # we generate a fake translation for en-US which is going to be
@@ -306,6 +341,7 @@
306341
307 def write_translated_markdown(self, po, po4a):342 def write_translated_markdown(self, po, po4a):
308 for po_fn in po.langs:343 for po_fn in po.langs:
344 po.langs[po_fn]['pofile'].readd_attr_list_statements()
309 for doc_fn in self.docs:345 for doc_fn in self.docs:
310 output = self._call_po4a_translate(doc_fn, po_fn, po4a)346 output = self._call_po4a_translate(doc_fn, po_fn, po4a)
311 title_line = output.split('\n')[0].split('Title: ')[1]347 title_line = output.split('\n')[0].split('Title: ')[1]
@@ -322,6 +358,7 @@
322 os.makedirs(os.path.dirname(new_path))358 os.makedirs(os.path.dirname(new_path))
323 with open(new_path, 'w', encoding='utf-8') as f:359 with open(new_path, 'w', encoding='utf-8') as f:
324 f.write(text)360 f.write(text)
361 po.langs[po_fn]['pofile'].hide_attr_list_statements()
325362
326363
327class Translations(object):364class Translations(object):

Subscribers

People subscribed via source and target branches