1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-28 11:15:58 +00:00
seahub/fabfile/locale.py

75 lines
2.5 KiB
Python
Raw Normal View History

2016-07-26 02:47:45 +00:00
# Copyright (c) 2012-2016 Seafile Ltd.
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
"""
2018-06-14 10:30:17 +00:00
import os
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
2016-03-21 02:59:24 +00:00
def make(default=True, lang='en'):
2014-12-26 07:09:30 +00:00
"""Update source language.
2014-11-01 03:50:56 +00:00
"""
2018-07-20 03:11:02 +00:00
# check branch name
with open('.git/HEAD') as f:
b1 = f.readline()
with open('../seahub-extra/.git/HEAD') as f:
b2 = f.readline()
if b1 != b2:
print 'Error: inconsistent Git branch names.'
return
2018-06-14 10:30:17 +00:00
# add strings in 'organization'
2018-06-15 06:33:23 +00:00
os.symlink('../../seahub-extra/seahub_extra/organizations', 'seahub/organizations')
2018-06-14 10:30:17 +00:00
local('django-admin.py makemessages -s -l %s -e py,html -i "thirdpart*" -i "docs*" -i "seahub/two_factor/gateways" -i "seahub/two_factor/templates/two_factor/core/otp_required.html" -i "seahub/two_factor/templates/two_factor/core/phone_register.html" -i "seahub/two_factor/templates/two_factor/profile/profile.html" -i "seahub/two_factor/models/phone.py" -i "seahub/two_factor/models/base.py" -i "seahub/two_factor/templates/two_factor/core/setup_complete.html"' % lang)
2018-06-14 10:30:17 +00:00
# remove 'organization' symlink to make codebase clean
os.remove('seahub/organizations')
2014-11-01 03:50:56 +00:00
# some version of makemessages will produce "%%" in the string, replace that
# to "%".
2016-03-21 02:59:24 +00:00
_inplace_change('locale/%s/LC_MESSAGES/django.po' % lang, '%%s', '%s')
_inplace_change('locale/%s/LC_MESSAGES/django.po' % lang, '%%(', '%(')
2014-11-01 03:50:56 +00:00
2018-08-31 05:19:19 +00:00
makejs(lang)
2015-04-14 09:17:05 +00:00
@task
2018-08-31 05:19:19 +00:00
def makejs(lang='en'):
local('django-admin.py makemessages -l %s -d djangojs -i "thirdpart" -i "node_modules" -i "media" -i "static/scripts/dist" -i "static/scripts/lib" -i "tests" -i "tools" -i "tagging" -i "static/scripts/i18n" -i "frontend/build" -i "frontend/config" -i "frontend/scripts" --verbosity 2' % lang)
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.
"""
2019-04-17 03:44:57 +00:00
local('tx -f pull')
2014-11-01 03:50:56 +00:00
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.
"""
2017-12-09 07:15:41 +00:00
local('django-admin.py compilemessages && pushd seahub/trusted_ip && django-admin.py compilemessages')
2014-11-01 03:58:42 +00:00
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())))