pep8
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import re
|
||||
import itertools
|
||||
|
||||
|
||||
class Converter(object):
|
||||
"""Converter is an abstract class that transforms strings.
|
||||
It hides embedded tags (HTML or Python sequences) from transformation
|
||||
@@ -20,7 +21,8 @@ class Converter(object):
|
||||
# matches tags like these:
|
||||
# HTML: <B>, </B>, <BR/>, <textformat leading="10">
|
||||
# Python: %(date)s, %(name)s
|
||||
tag_pattern = re.compile(r'''
|
||||
tag_pattern = re.compile(
|
||||
r'''
|
||||
(<[^>]+>) | # <tag>
|
||||
({[^}]+}) | # {tag}
|
||||
(%\([\w]+\)\w) | # %(tag)s
|
||||
@@ -28,7 +30,7 @@ class Converter(object):
|
||||
(&\#\d+;) | # Ӓ
|
||||
(&\#x[0-9a-f]+;) # ꯍ
|
||||
''',
|
||||
re.IGNORECASE|re.VERBOSE
|
||||
re.IGNORECASE | re.VERBOSE
|
||||
)
|
||||
|
||||
def convert(self, string):
|
||||
@@ -55,7 +57,7 @@ class Converter(object):
|
||||
tags = [''.join(tag) for tag in tags]
|
||||
(new, nfound) = self.tag_pattern.subn(count, string)
|
||||
if len(tags) != nfound:
|
||||
raise Exception('tags dont match:'+string)
|
||||
raise Exception('tags dont match:' + string)
|
||||
return (new, tags)
|
||||
|
||||
def retag_string(self, string, tags):
|
||||
@@ -65,7 +67,6 @@ class Converter(object):
|
||||
string = re.sub(p, tag, string, 1)
|
||||
return string
|
||||
|
||||
|
||||
# ------------------------------
|
||||
# Customize this in subclasses of Converter
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import os, subprocess, logging
|
||||
import os
|
||||
import subprocess
|
||||
import logging
|
||||
|
||||
from i18n.config import BASE_DIR
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def execute(command, working_directory=BASE_DIR, stderr=subprocess.STDOUT):
|
||||
"""
|
||||
Executes shell command in a given working_directory.
|
||||
|
||||
@@ -35,6 +35,7 @@ EDX_MARKER = "edX translation file"
|
||||
LOG = logging.getLogger(__name__)
|
||||
DEVNULL = open(os.devnull, 'wb')
|
||||
|
||||
|
||||
def base(path1, *paths):
|
||||
"""Return a relative path from BASE_DIR to path1 / paths[0] / ... """
|
||||
return BASE_DIR.relpathto(path1.joinpath(*paths))
|
||||
@@ -143,20 +144,24 @@ def fix_header(po):
|
||||
fixes = (
|
||||
('SOME DESCRIPTIVE TITLE', EDX_MARKER),
|
||||
('Translations template for PROJECT.', EDX_MARKER),
|
||||
('YEAR', '%s' % datetime.utcnow().year),
|
||||
('YEAR', str(datetime.utcnow().year)),
|
||||
('ORGANIZATION', 'edX'),
|
||||
("THE PACKAGE'S COPYRIGHT HOLDER", "EdX"),
|
||||
('This file is distributed under the same license as the PROJECT project.',
|
||||
'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'),
|
||||
('This file is distributed under the same license as the PACKAGE package.',
|
||||
'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'),
|
||||
('FIRST AUTHOR <EMAIL@ADDRESS>',
|
||||
'EdX Team <info@edx.org>')
|
||||
)
|
||||
(
|
||||
'This file is distributed under the same license as the PROJECT project.',
|
||||
'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'
|
||||
),
|
||||
(
|
||||
'This file is distributed under the same license as the PACKAGE package.',
|
||||
'This file is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.'
|
||||
),
|
||||
('FIRST AUTHOR <EMAIL@ADDRESS>', 'EdX Team <info@edx.org>'),
|
||||
)
|
||||
for src, dest in fixes:
|
||||
header = header.replace(src, dest)
|
||||
po.header = header
|
||||
|
||||
|
||||
def fix_metadata(po):
|
||||
"""
|
||||
Replace default metadata with edX metadata
|
||||
@@ -179,12 +184,13 @@ def fix_metadata(po):
|
||||
'PO-Revision-Date': datetime.utcnow(),
|
||||
'Report-Msgid-Bugs-To': 'openedx-translation@googlegroups.com',
|
||||
'Project-Id-Version': '0.1a',
|
||||
'Language' : 'en',
|
||||
'Last-Translator' : '',
|
||||
'Language': 'en',
|
||||
'Last-Translator': '',
|
||||
'Language-Team': 'openedx-translation <openedx-translation@googlegroups.com>',
|
||||
}
|
||||
po.metadata.update(fixes)
|
||||
|
||||
|
||||
def strip_key_strings(po):
|
||||
"""
|
||||
Removes all entries in PO which are key strings.
|
||||
@@ -194,6 +200,7 @@ def strip_key_strings(po):
|
||||
del po[:]
|
||||
po += newlist
|
||||
|
||||
|
||||
def is_key_string(string):
|
||||
"""
|
||||
returns True if string is a key string.
|
||||
@@ -201,6 +208,7 @@ def is_key_string(string):
|
||||
"""
|
||||
return len(string) > 1 and string[0] == '_'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--verbose', '-v', action='count', default=0)
|
||||
|
||||
@@ -16,6 +16,7 @@ from i18n.converter import Converter
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def validate_po_files(root, report_empty=False):
|
||||
"""
|
||||
Validate all of the po files found in the root directory.
|
||||
|
||||
Reference in New Issue
Block a user