Created
September 23, 2013 19:15
-
-
Save Ivoz/6675429 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from os.path import join | |
from fabric.api import local | |
BASE_DIR = os.path.realpath(os.path.dirname(__file__)) | |
BUILD_DIR = join(BASE_DIR, '_build') | |
SOURCE_DIR = join(BASE_DIR, 'source') | |
LOCALE_DIR = join(SOURCE_DIR, 'locale', | |
'%s', 'LC_MESSAGES') | |
NEW_DIR = join(BUILD_DIR, 'merged') | |
OLD_FILE = join(SOURCE_DIR, '_locales', 'de', 'LC_MESSAGES', 'pybeginners.po') | |
def merge(): | |
local('mkdir -p %s' % NEW_DIR) | |
for po in os.listdir(LOCALE_DIR % 'de'): | |
args = [ | |
'msgmerge', | |
'-o ' + join(NEW_DIR, po), | |
'-C ' + OLD_FILE, | |
join(LOCALE_DIR % 'de', po), | |
join(BUILD_DIR, 'locale', 'de', po + 't'), | |
] | |
local(' '.join(args)) | |
blurb = """# Copyright (C) 2012, OpenTechSchool and contributors | |
# This file is distributed under the same license as the Introduction to Programming with Python package. | |
# | |
# Translators: | |
# lightyear <[email protected]>, 2013 | |
# krother <[email protected]>, 2013 | |
# lehmannro <[email protected]>, 2013 | |
""" | |
def fixup(): | |
for po in os.listdir(LOCALE_DIR % 'de'): | |
po_lines = open(join(LOCALE_DIR % 'de', po)).readlines() | |
for i, l in enumerate(po_lines): | |
if l.startswith('"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"'): | |
po_lines[i] = '"PO-Revision-Date: 2013-09-03 19:34+0000\\n"\n' | |
if l.startswith('"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"'): | |
po_lines[i] = '"Last-Translator: krother <[email protected]>\\n"\n' | |
if l.startswith('"Language-Team: LANGUAGE <[email protected]>\\n"'): | |
po_lines[i] = '"Language-Team: German (http://www.transifex.com/projects/p/python-for-beginners/language/de/)\\n"\n' | |
if l.startswith('"Language: \\n"'): | |
po_lines[i] = '"Language: de\\n"\n' | |
if l.startswith('# '): | |
po_lines[i] = None | |
po_lines[0] = blurb | |
newpo = open(join(SOURCE_DIR,'locale/de', 'fixed', po), 'w') | |
newpo.writelines(line for line in po_lines if line is not None) | |
if __name__ == "__main__": | |
print(sys.argv) | |
if sys.argv[1] == 'merge': | |
merge() | |
elif sys.argv[1] == 'fixup': | |
fixup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment