3
from django.core.management.base import LabelCommand
11
from django.conf import settings
14
APP_NAME = settings.LP_PROJECT_NAME
15
except AttributeError:
16
# if you prefer not to set LP_PROJECT_NAME in settings.py, define here
17
APP_NAME = "loco-directory"
20
def import_pofile(pofile):
21
locale = re.findall("^%s-(.*).po$" % APP_NAME, os.path.basename(pofile))
24
project_locale_path = os.path.join(settings.PROJECT_PATH, "locale", locale[0])
25
if not os.path.exists(project_locale_path) or \
26
not os.path.isdir(project_locale_path):
28
os.chdir(settings.PROJECT_PATH)
29
print settings.PROJECT_PATH
30
subprocess.call(["./manage.py", "makemessages", "-l", locale[0]])
32
subprocess.call(["cp", pofile,
33
os.path.join(project_locale_path,
34
"LC_MESSAGES/django.po")])
36
class Command(LabelCommand):
37
help = "Import translations from a translations tarball, that was downloaded from Launchpad."
39
def handle_label(self, label, **options):
40
if not os.path.exists(label):
41
print >> sys.stderr, "File not found: %s" % label
43
if not label.endswith(".tar.gz") and not label.endswith(".tgz"):
44
print >> sys.stderr, "File is not a .tar.gz file: %s" % label
48
dir = tempfile.mkdtemp(APP_NAME)
49
subprocess.call(["cp", label, dir])
51
subprocess.call(["tar", "xfz", os.path.basename(label)])
53
for dirpath, dirnames, filenames in os.walk(dir):
54
pofiles = map(lambda a: os.path.join(dirpath, a),
55
filter(lambda a: a.endswith(".po"), filenames))
56
for pofile in pofiles:
60
subprocess.call(["rm", "-r", dir])
61
print "Make sure, you 'bzr add' all the new translations."