+ CounterFormat = re.compile(r'^\s*PrettyFormat\s+"?(.*)"?\s*$', re.IGNORECASE)
+ CiteFormat = re.compile(r'^\s*CiteFormat', re.IGNORECASE)
+ # Note: preceding and trailing space in the val below matters
+ KeyVal = re.compile(r'^\s*_\w+\s(.*\S)*$')
+ Float = re.compile(r'^\s*Float\s*$', re.IGNORECASE)
+ UsesFloatPkg = re.compile(r'^\s*UsesFloatPkg\s+(.*\S)\s*$', re.IGNORECASE)
+ IsPredefined = re.compile(r'^\s*IsPredefined\s+(.*\S)\s*$', re.IGNORECASE)
+ End = re.compile(r'^\s*End', re.IGNORECASE)
+ Comment = re.compile(r'^(.*)#')
+ Translation = re.compile(r'^\s*Translation\s+(.*\S)\s*$', re.IGNORECASE)
+ KeyValPair = re.compile(r'\s*"(.*)"\s+"(.*)"')
+
+ oldlanguages = []
+ languages = []
+ keyset = set()
+ oldtrans = dict()
+ if layouttranslations:
+ linguas_file = os.path.join(base, 'po/LINGUAS')
+ for line in open(linguas_file).readlines():
+ res = Comment.search(line)
+ if res:
+ line = res.group(1)
+ if line.strip() != '':
+ languages.extend(line.split())
+
+ # read old translations if available
+ try:
+ input = io.open(output, encoding='utf_8')
+ lang = ''
+ for line in input.readlines():
+ res = Comment.search(line)
+ if res:
+ line = res.group(1)
+ if line.strip() == '':
+ continue
+ res = Translation.search(line)
+ if res:
+ lang = res.group(1)
+ if lang not in languages:
+ oldlanguages.append(lang)
+ languages.append(lang)
+ oldtrans[lang] = dict()
+ continue
+ res = End.search(line)
+ if res:
+ lang = ''
+ continue
+ res = KeyValPair.search(line)
+ if res and lang != '':
+ key = res.group(1)
+ val = res.group(2)
+ key = key.replace('\\"', '"').replace('\\\\', '\\')
+ val = val.replace('\\"', '"').replace('\\\\', '\\')
+ oldtrans[lang][key] = val
+ keyset.add(key)
+ continue
+ print("Error: Unable to handle line:")
+ print(line)
+ except IOError:
+ print("Warning: Unable to open %s for reading." % output)
+ print(" Old translations will be lost.")
+
+ # walon is not a known document language
+ # FIXME: Do not hardcode, read from lib/languages!
+ if 'wa' in languages:
+ languages.remove('wa')
+
+ if layouttranslations:
+ out = io.open(output, 'w', encoding='utf_8')
+ else:
+ out = io.open(output, 'w', encoding='utf_8', newline='\n')