Skip to content

Commit

Permalink
[#2774] I18n js build translation refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 6, 2012
1 parent 771b5bc commit 493324f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions ckan/lib/cli.py
Expand Up @@ -1567,20 +1567,22 @@ def build_js_translations(self):
import polib
import simplejson as json

out_dir = os.path.abspath(os.path.join(self.ckan_path, 'public',
'base', 'i18n'))
def create_js(source, lang):
print 'Generating', lang
po = polib.pofile(source)
data = self.po2dict(po, lang)
data = json.dumps(data, sort_keys=True,
ensure_ascii=False, indent=2 * ' ')
out_dir = os.path.abspath(os.path.join(self.ckan_path, 'public',
'base', 'i18n'))
out_file = open(os.path.join(out_dir, '%s.js' % lang), 'w')
out_file.write(data.encode('utf-8'))
out_file.close()

for l in os.listdir(self.i18n_path):
if os.path.isdir(os.path.join(self.i18n_path, l)):
print 'Generating', l
f = os.path.join(self.i18n_path, l, 'LC_MESSAGES', 'ckan.po')
po = polib.pofile(f)
data = self.po2dict(po, l)
data = json.dumps(data, sort_keys=True,
ensure_ascii=False, indent=2 * ' ')
out_file = open(os.path.join(out_dir, '%s.js' % l), 'w')
out_file.write(data.encode('utf-8'))
out_file.close()

create_js(f, l)
print 'Completed generating JavaScript translations'

def mangle_po(self):
Expand Down

0 comments on commit 493324f

Please sign in to comment.