mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 01:10:09 +00:00
Temp
This commit is contained in:
parent
fd4b815cb4
commit
563d64568b
@ -32,7 +32,7 @@ def _get_content_from_file(filename: str, encoding: str):
|
|||||||
except IOError as e:
|
except IOError as e:
|
||||||
print("Error opening file %s with encoding %s: %s" % (filename, encoding, e.message))
|
print("Error opening file %s with encoding %s: %s" % (filename, encoding, e.message))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Unhandled exception: %s" % e.message)
|
print("Unhandled exception: %s" % e)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ def parse_strings(filename: str):
|
|||||||
f = f.lstrip(u'\ufeff')
|
f = f.lstrip(u'\ufeff')
|
||||||
# regex for finding all comments in a file
|
# regex for finding all comments in a file
|
||||||
cp = r'(?:/\*(?P<comment>(?:[^*]|(?:\*+[^*/]))*\**)\*/)'
|
cp = r'(?:/\*(?P<comment>(?:[^*]|(?:\*+[^*/]))*\**)\*/)'
|
||||||
p = re.compile(r'(?:%s[ \t]*[\n]|[\r\n]|[\r]){0,1}(?P<line>(("(?P<key>[^"\\]*(?:\\.[^"\\]*)*)")|('
|
p = re.compile(r'(?:%s[ \t]*[\n]|[\r\n]|[\r])?(?P<line>(("(?P<key>[^"\\]*(?:\\.[^"\\]*)*)")|('
|
||||||
r'?P<property>\w+))\s*=\s*"(?P<value>[^"\\]*(?:\\.[^"\\]*)*)"\s*;)' % cp, re.DOTALL | re.U)
|
r'?P<property>\w+))\s*=\s*"(?P<value>[^"\\]*(?:\\.[^"\\]*)*)"\s*;)' % cp, re.DOTALL | re.U)
|
||||||
c = re.compile(r'//[^\n]*\n|/\*(?:.|[\r\n])*?\*/', re.U)
|
c = re.compile(r'//[^\n]*\n|/\*(?:.|[\r\n])*?\*/', re.U)
|
||||||
ws = re.compile(r'\s+', re.U)
|
ws = re.compile(r'\s+', re.U)
|
||||||
@ -69,12 +69,55 @@ def parse_strings(filename: str):
|
|||||||
return stringset
|
return stringset
|
||||||
|
|
||||||
|
|
||||||
|
class PositionalArgument:
|
||||||
|
def __init__(self, index: int, kind: str):
|
||||||
|
self.index = index
|
||||||
|
self.kind = kind
|
||||||
|
|
||||||
|
|
||||||
class Entry:
|
class Entry:
|
||||||
def __init__(self, is_pluralized: bool, positional_arguments: [str]):
|
def __init__(self, is_pluralized: bool, positional_arguments: [PositionalArgument]):
|
||||||
self.is_pluralized = is_pluralized
|
self.is_pluralized = is_pluralized
|
||||||
self.positional_arguments = positional_arguments
|
self.positional_arguments = positional_arguments
|
||||||
|
|
||||||
|
|
||||||
|
def parse_positional_arguments(string: str) -> [PositionalArgument]:
|
||||||
|
result = list()
|
||||||
|
|
||||||
|
implicit_index = 0
|
||||||
|
argument = re.compile(r'%((\d)\$)?([@d])', re.U)
|
||||||
|
start_position = 0
|
||||||
|
while True:
|
||||||
|
m = argument.search(string, start_position)
|
||||||
|
if m is None:
|
||||||
|
break
|
||||||
|
index = m.group(2)
|
||||||
|
if index is None:
|
||||||
|
index = implicit_index
|
||||||
|
implicit_index += 1
|
||||||
|
else:
|
||||||
|
index = int(index)
|
||||||
|
kind = m.group(3)
|
||||||
|
result.append(PositionalArgument(index=index, kind=kind))
|
||||||
|
start_position = m.end(0)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def parse_entries(strings: [dict]):
|
||||||
|
entries = dict()
|
||||||
|
pluralized = re.compile(r'^(.*?)_(0|1|2|3_10|many|any)$', re.U)
|
||||||
|
for string in strings:
|
||||||
|
key = string['key']
|
||||||
|
m = pluralized.match(key)
|
||||||
|
if m is not None:
|
||||||
|
raw_key = m.group(1)
|
||||||
|
if raw_key not in entries:
|
||||||
|
entries[raw_key] = Entry(is_pluralized=True, positional_arguments=[])
|
||||||
|
else:
|
||||||
|
entries[key] = Entry(is_pluralized=False, positional_arguments=parse_positional_arguments(string['value']))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser(prog='GenerateStrings')
|
parser = argparse.ArgumentParser(prog='GenerateStrings')
|
||||||
|
|
||||||
@ -104,4 +147,4 @@ if __name__ == '__main__':
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
parsed_strings = parse_strings(args.source)
|
parsed_strings = parse_strings(args.source)
|
||||||
print(parsed_strings)
|
parse_entries(parsed_strings)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user