1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-28 19:25:03 +00:00
seahub/fabfile/locale.py

51 lines
1.3 KiB
Python
Raw Normal View History

2014-11-01 03:50:56 +00:00
"""
2014-11-01 05:40:07 +00:00
Tools for i18n.
2014-11-01 03:50:56 +00:00
"""
2014-11-01 05:40:07 +00:00
from fabric.api import local, task
2014-11-01 03:50:56 +00:00
from fabric.colors import red, green
2014-11-01 05:40:07 +00:00
@task
2014-12-26 07:09:30 +00:00
def make(default=True):
"""Update source language.
2014-11-01 03:50:56 +00:00
"""
2014-12-26 07:09:30 +00:00
local('django-admin.py makemessages -l en -e py,html -i "thirdpart*" -i "docs*"')
2014-11-01 03:50:56 +00:00
# some version of makemessages will produce "%%" in the string, replace that
# to "%".
2014-12-26 09:21:01 +00:00
_inplace_change('locale/en/LC_MESSAGES/django.po', '%%s', '%s')
_inplace_change('locale/en/LC_MESSAGES/django.po', '%%(', '%(')
2014-11-01 03:50:56 +00:00
2015-04-14 09:17:05 +00:00
local('django-admin.py makemessages -l en -d djangojs -i "thirdpart" -i "node_modules" -i "media" -i "static/scripts/dist" -i "static/scripts/lib" -i "tests" ')
2014-12-26 07:09:30 +00:00
@task
def push():
"""Push source file to Transifex.
"""
2014-11-01 03:50:56 +00:00
local('tx push -s')
2014-11-01 05:40:07 +00:00
@task
def pull():
2014-11-01 03:50:56 +00:00
"""Update local po files with Transifex.
"""
local('tx pull')
2014-12-26 07:09:30 +00:00
@task()
2014-11-01 05:40:07 +00:00
def compile():
2014-11-01 03:58:42 +00:00
"""Compile po files.
"""
local('django-admin.py compilemessages')
2014-11-01 03:50:56 +00:00
########## utility functions
def _inplace_change(filename, old_string, new_string):
s = open(filename).read()
if old_string in s:
print(green('Changing "{old_string}" to "{new_string}" in "{filename}"'.format(**locals())))
s = s.replace(old_string, new_string)
f = open(filename, 'w')
f.write(s)
f.flush()
f.close()
def _debug(msg):
print(red('Running: {msg}'.format(**locals())))