Commit bec2ca40 by Steve Strassmann

cleanup headers of files pulled from transifex.

parent 65dd3cc9
{
"locales" : ["en"],
"locales" : ["en", "es"],
"dummy-locale" : "fr"
}
......@@ -2,6 +2,12 @@
# Generate test translation files from human-readable po files.
#
# Dummy language is specified in configuration file (see config.py)
# two letter language codes reference:
# see http://www.loc.gov/standards/iso639-2/php/code_list.php
#
# Django will not localize in languages that django itself has not been
# localized for. So we are using a well-known language (default='fr').
#
# po files can be generated with this:
# django-admin.py makemessages --all --extension html -l en
......@@ -18,7 +24,8 @@
import os, sys
import polib
from dummy import Dummy
from execute import get_logger, create_dir_if_necessary
from config import CONFIGURATION
from execute import create_dir_if_necessary
def main(file, locale):
"""
......@@ -47,21 +54,13 @@ def new_filename(original_filename, new_locale):
msgs_dir,
orig_file))
# Dummy language
# two letter language codes reference:
# see http://www.loc.gov/standards/iso639-2/php/code_list.php
#
# Django will not localize in languages that django itself has not been
# localized for. So we are using a well-known language: 'fr'.
DEFAULT_LOCALE = 'fr'
if __name__ == '__main__':
# required arg: file
if len(sys.argv)<2:
raise Exception("missing file argument")
# optional arg: locale
if len(sys.argv)<3:
locale = DEFAULT_LOCALE
locale = CONFIGURATION.get_dummy_locale()
else:
locale = sys.argv[2]
main(sys.argv[1], locale)
#!/usr/bin/python
import sys
import os, sys
from polib import pofile
from config import CONFIGURATION
from extract import SOURCE_WARN
from execute import execute
TRANSIFEX_HEADER = 'Translations in this file have been downloaded from %s'
TRANSIFEX_URL = 'https://www.transifex.com/projects/p/edx-studio/'
def push():
execute('tx push -s')
def pull():
execute('tx pull')
clean_translated_locales()
def clean_translated_locales():
"""
Strips out the warning from all translated po files
about being an English source file.
"""
for locale in CONFIGURATION.get_locales():
if locale != CONFIGURATION.get_source_locale():
clean_locale(locale)
def clean_locale(locale):
"""
Strips out the warning from all of a locale's translated po files
about being an English source file.
Iterates over machine-generated files.
"""
dirname = CONFIGURATION.get_messages_dir(locale)
for filename in ('django-partial.po', 'djangojs.po', 'mako.po'):
clean_file(os.path.join(dirname, filename))
def clean_file(file):
"""
Strips out the warning from a translated po file about being an English source file.
Replaces warning with a note about coming from Transifex.
"""
po = pofile(file)
if po.header.find(SOURCE_WARN) != -1:
new_header = get_new_header(po)
new = po.header.replace(SOURCE_WARN, new_header)
po.header = new
po.save()
def get_new_header(po):
team = po.metadata.get('Language-Team', None)
if not team:
return TRANSIFEX_HEADER % TRANSIFEX_URL
else:
return TRANSIFEX_HEADER % team
if __name__ == '__main__':
if len(sys.argv)<2:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment