~webapps/unity-firefox-extension/quantal

« back to all changes in this revision

Viewing changes to po/import_translations.py

  • Committer: Ken VanDine
  • Date: 2012-10-01 19:26:03 UTC
  • mfrom: (83.37.53)
  • Revision ID: ken.vandine@canonical.com-20121001192603-y07phsf5gugx7s2t
Tags: 2.3.3-0ubuntu1
releasing version 2.3.3-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
import polib
3
 
import codecs
4
 
import sys
5
 
import os
6
 
import re
7
 
import optparse
8
 
 
9
 
scriptPath = os.path.realpath(__file__)
10
 
rootSrcDir = os.path.dirname(os.path.dirname(scriptPath))
11
 
 
12
 
def save(lang, translation):
13
 
    lang = lang.replace('_', '-')
14
 
    if not os.path.isdir(rootSrcDir + '/unity-firefox-extension/locale/' + lang):
15
 
        os.mkdir(rootSrcDir + '/unity-firefox-extension/locale/' + lang)
16
 
        print('created ' + rootSrcDir + '/unity-firefox-extension/locale/' + lang)
17
 
 
18
 
        manifest = open(rootSrcDir + '/unity-firefox-extension/chrome.manifest', 'a')
19
 
        manifest.write('locale unity ' + lang + ' locale/' + lang + '/\n')
20
 
        manifest.close()
21
 
    lines = open(rootSrcDir + '/unity-firefox-extension/locale/en-US/unity_webapps.properties', 'r').readlines()
22
 
 
23
 
    out = codecs.open(rootSrcDir + '/unity-firefox-extension/locale/' + lang + '/unity_webapps.properties', "w", "utf-8")
24
 
    for line in lines:
25
 
        msg = line[line.find('=') + 1:].strip()
26
 
        id = line[:line.find('=')].strip()
27
 
        if msg in translation:
28
 
            msg = translation[msg]
29
 
        out.write(id + ' = ' + msg + '\n')
30
 
    out.close()
31
 
 
32
 
for root, dirs, files in os.walk(rootSrcDir + '/po'):
33
 
    for name in files:
34
 
        match = re.search('(.+)\.po$', name)
35
 
        if not match:
36
 
            continue
37
 
        lang = match.groups()[0]
38
 
        po = polib.pofile(os.path.join(root, name))
39
 
        t = {}
40
 
        for entry in po:
41
 
            if entry.obsolete or entry.msgstr == '':
42
 
                continue
43
 
            t[entry.msgid] = entry.msgstr;
44
 
        save(lang, t)