Merge lp:~dholbach/help-app/translations-module into lp:~ubuntu-touch-coreapps-drivers/help-app/trunk

Proposed by Daniel Holbach
Status: Merged
Merged at revision: 38
Proposed branch: lp:~dholbach/help-app/translations-module
Merge into: lp:~ubuntu-touch-coreapps-drivers/help-app/trunk
Diff against target: 163 lines (+74/-72)
2 files modified
edit-here/generate-pot (+1/-72)
edit-here/translations.py (+73/-0)
To merge this branch: bzr merge lp:~dholbach/help-app/translations-module
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Approve
Review via email: mp+249222@code.launchpad.net

Description of the change

Break all the translations functionality into its own python module.

To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

approve. metadata_tags are being updated in the next mp.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'edit-here/generate-pot'
2--- edit-here/generate-pot 2015-02-10 15:29:15 +0000
3+++ edit-here/generate-pot 2015-02-10 17:24:22 +0000
4@@ -3,80 +3,9 @@
5 # We need this script to help us generate a .pot file, which does not
6 # contain the meta-data strings at the top of the markdown files.
7
8-import glob
9-import os
10-import shutil
11-import subprocess
12 import sys
13
14-from pelicanconf import PATH
15-
16-METADATA_TAGS = [
17- 'title',
18- 'lang',
19- 'date',
20- 'save_as',
21- ]
22-
23-
24-class Translations(object):
25- def __init__(self):
26- self._cleanup()
27- self.translations_dir = os.path.abspath(os.path.join(PATH, '../po'))
28- self.available_languages = list(
29- map(lambda a: os.path.basename(a).split('.po')[0],
30- glob.glob(self.translations_dir+'/*.po')))
31- self.documents = self._find_documents()
32-
33- def _find_documents(self):
34- documents = []
35- for dirpath, dirnames, filenames in os.walk(PATH):
36- for filename in filenames:
37- documents += [os.path.join(dirpath, filename)]
38- return documents
39-
40- def _cleanup(self):
41- pwd = os.getcwd()
42- os.chdir(os.path.join(PATH, '../..'))
43- subprocess.call(['make', 'clean'])
44- os.chdir(pwd)
45-
46- def backup_documents(self):
47- shutil.copytree(PATH, os.path.join(PATH, '../backup/'))
48-
49- def _remove_metadata(self, filename):
50- lines = open(filename).readlines()
51- index = 0
52- for line in lines:
53- if not [x for x in METADATA_TAGS if line.startswith(x+':')] and \
54- line.strip()!='':
55- index = lines.index(line)
56- break
57- os.remove(filename)
58- with open(filename, 'w', encoding='utf-8') as new_file:
59- new_file.write(''.join(lines[index:]))
60-
61- def clean_documents(self):
62- for document in self.documents:
63- self._remove_metadata(document)
64-
65- def generate_pot_file(self):
66- args = [
67- '-f', 'text',
68- '-o', 'markdown',
69- '-M', 'utf-8',
70- '-L', 'utf-8',
71- ]
72- for document in self.documents:
73- args += [ '-m', document ]
74- args += [
75- '-p', os.path.join(self.translations_dir, 'help.pot')
76- ]
77- subprocess.call([ 'po4a-gettextize' ]+args)
78-
79- def copy_backuped_data_back(self):
80- shutil.rmtree(PATH)
81- shutil.copytree(os.path.join('backup'), PATH)
82+from translations import Translations
83
84
85 def main():
86
87=== added file 'edit-here/translations.py'
88--- edit-here/translations.py 1970-01-01 00:00:00 +0000
89+++ edit-here/translations.py 2015-02-10 17:24:22 +0000
90@@ -0,0 +1,73 @@
91+import glob
92+import os
93+import shutil
94+import subprocess
95+
96+from pelicanconf import PATH
97+
98+METADATA_TAGS = [
99+ 'title',
100+ 'lang',
101+ 'date',
102+ 'save_as',
103+ ]
104+
105+
106+class Translations(object):
107+ def __init__(self):
108+ self._cleanup()
109+ self.translations_dir = os.path.abspath(os.path.join(PATH, '../po'))
110+ self.available_languages = list(
111+ map(lambda a: os.path.basename(a).split('.po')[0],
112+ glob.glob(self.translations_dir+'/*.po')))
113+ self.documents = self._find_documents()
114+
115+ def _find_documents(self):
116+ documents = []
117+ for dirpath, dirnames, filenames in os.walk(PATH):
118+ for filename in filenames:
119+ documents += [os.path.join(dirpath, filename)]
120+ return documents
121+
122+ def _cleanup(self):
123+ pwd = os.getcwd()
124+ os.chdir(os.path.join(PATH, '../..'))
125+ subprocess.call(['make', 'clean'])
126+ os.chdir(pwd)
127+
128+ def backup_documents(self):
129+ shutil.copytree(PATH, os.path.join(PATH, '../backup/'))
130+
131+ def _remove_metadata(self, filename):
132+ lines = open(filename).readlines()
133+ index = 0
134+ for line in lines:
135+ if not [x for x in METADATA_TAGS if line.startswith(x+':')] and \
136+ line.strip()!='':
137+ index = lines.index(line)
138+ break
139+ os.remove(filename)
140+ with open(filename, 'w', encoding='utf-8') as new_file:
141+ new_file.write(''.join(lines[index:]))
142+
143+ def clean_documents(self):
144+ for document in self.documents:
145+ self._remove_metadata(document)
146+
147+ def generate_pot_file(self):
148+ args = [
149+ '-f', 'text',
150+ '-o', 'markdown',
151+ '-M', 'utf-8',
152+ '-L', 'utf-8',
153+ ]
154+ for document in self.documents:
155+ args += [ '-m', document ]
156+ args += [
157+ '-p', os.path.join(self.translations_dir, 'help.pot')
158+ ]
159+ subprocess.call([ 'po4a-gettextize' ]+args)
160+
161+ def copy_backuped_data_back(self):
162+ shutil.rmtree(PATH)
163+ shutil.copytree(os.path.join('backup'), PATH)

Subscribers

People subscribed via source and target branches