Index: localeTools.py |
diff --git a/localeTools.py b/localeTools.py |
index b140e6db664f7f9264409c66fc4a98855d52ad19..d5827f1f976d3134381d11275e3a4ccb95615586 100644 |
--- a/localeTools.py |
+++ b/localeTools.py |
@@ -161,35 +161,6 @@ def mapLocale(type, locale): |
return mapping.get(locale, locale) |
-def parseDTDString(data, path): |
- result = [] |
- currentComment = [None] |
- |
- parser = ParserCreate() |
- parser.UseForeignDTD(True) |
- parser.SetParamEntityParsing(XML_PARAM_ENTITY_PARSING_ALWAYS) |
- |
- def ExternalEntityRefHandler(context, base, systemId, publicId): |
- subparser = parser.ExternalEntityParserCreate(context, 'utf-8') |
- subparser.Parse(data.encode('utf-8'), True) |
- return 1 |
- |
- def CommentHandler(data): |
- currentComment[0] = data.strip() |
- |
- def EntityDeclHandler(entityName, is_parameter_entity, value, base, systemId, publicId, notationName): |
- result.append((unescapeEntity(entityName), currentComment[0], unescapeEntity(value.strip()))) |
- currentComment[0] = None |
- |
- parser.ExternalEntityRefHandler = ExternalEntityRefHandler |
- parser.CommentHandler = CommentHandler |
- parser.EntityDeclHandler = EntityDeclHandler |
- parser.Parse('<!DOCTYPE root SYSTEM "foo"><root/>', True) |
- |
- for entry in result: |
- yield entry |
- |
- |
def escapeProperty(value): |
return value.replace('\n', '\\n') |
@@ -214,9 +185,7 @@ def parsePropertiesString(data, path): |
def parseString(data, path): |
result = {'_origData': data} |
- if path.endswith('.dtd'): |
- it = parseDTDString(data, path) |
- elif path.endswith('.properties'): |
+ if path.endswith('.properties'): |
Sebastian Noack
2017/10/03 02:22:39
Both, the .dtd and the .properties format are spec
tlucas
2017/10/04 11:48:38
Done.
|
it = parsePropertiesString(data, path) |
else: |
return None |
@@ -233,21 +202,12 @@ def readFile(path): |
return parseString(data, path) |
-def generateStringEntry(key, value, path): |
- if path.endswith('.dtd'): |
- return '<!ENTITY %s "%s">\n' % (escapeEntity(key), escapeEntity(value)) |
- else: |
- return '%s=%s\n' % (escapeProperty(key), escapeProperty(value)) |
- |
- |
def toJSON(path): |
fileHandle = codecs.open(path, 'rb', encoding='utf-8') |
data = fileHandle.read() |
fileHandle.close() |
- if path.endswith('.dtd'): |
- it = parseDTDString(data, path) |
- elif path.endswith('.properties'): |
+ if path.endswith('.properties'): |
it = parsePropertiesString(data, path) |
else: |
return None |
@@ -275,7 +235,8 @@ def fromJSON(path, data): |
os.makedirs(dir) |
file = codecs.open(path, 'wb', encoding='utf-8') |
for key, value in data.iteritems(): |
- file.write(generateStringEntry(key, value['message'], path)) |
+ file.write('{}={}\n'.format(escapeProperty(key), |
+ escapeProperty(value['message']))) |
file.close() |
@@ -324,7 +285,7 @@ def setupTranslations(localeConfig, projectName, key): |
for locale in chromeLocales: |
locales.add(mapLocale('ISO-15897', locale)) |
- if 'gecko' in localeConfig['target_platforms']: |
+ if 'gecko-webext' in localeConfig['target_platforms']: |
firefoxLocales = urllib2.urlopen('http://www.mozilla.org/en-US/firefox/all.html').read() |
for match in re.finditer(r'&lang=([\w\-]+)"', firefoxLocales): |
locales.add(mapLocale('BCP-47', match.group(1))) |
@@ -476,10 +437,6 @@ def getTranslations(localeConfig, projectName, key): |
origFile = file |
else: |
origFile = re.sub(r'\.json$', '', file) |
- if (localeConfig['file_format'] == 'gecko-dtd' and |
- not origFile.endswith('.dtd') and |
- not origFile.endswith('.properties')): |
- continue |
if localeConfig['name_format'] == 'ISO-15897': |
mapping = langMappingChrome |
@@ -521,5 +478,7 @@ def getTranslations(localeConfig, projectName, key): |
continue |
for file in os.listdir(baseDir): |
path = os.path.join(baseDir, file) |
- if os.path.isfile(path) and (file.endswith('.json') or file.endswith('.properties') or file.endswith('.dtd')) and not file in files: |
+ valid_extension = os.path.splitext(file)[1] in {'.json', |
+ '.properties'} |
+ if os.path.isfile(path) and valid_extension and not file in files: |
os.remove(path) |