Changeset View
Changeset View
Standalone View
Standalone View
source/tools/i18n/extractors/extractors.py
# -*- coding:utf-8 -*- | # -*- coding:utf-8 -*- | ||||
# | # | ||||
# Copyright (C) 2016 Wildfire Games. | # Copyright (C) 2020 Wildfire Games. | ||||
# All rights reserved. | # All rights reserved. | ||||
# | # | ||||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||||
# following conditions are met: | # following conditions are met: | ||||
# | # | ||||
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following | # Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||||
# disclaimer. | # disclaimer. | ||||
# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | # Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | def extractJavascriptFromFile(self, fileObject): | ||||
translator_comments = [] | translator_comments = [] | ||||
concatenate_next = False | concatenate_next = False | ||||
last_token = None | last_token = None | ||||
call_stack = -1 | call_stack = -1 | ||||
comment_tags = self.options.get('commentTags', []) | comment_tags = self.options.get('commentTags', []) | ||||
keywords = self.options.get('keywords', {}).keys() | keywords = self.options.get('keywords', {}).keys() | ||||
for token in tokenize(fileObject.read()): | for token in tokenize(fileObject.read()): | ||||
if token.type == 'operator' and token.value == '(': | if token.type == 'operator' and \ | ||||
(token.value == '(' or (call_stack != -1 and \ | |||||
(token.value == '[' or token.value == '{'))): | |||||
if funcname: | if funcname: | ||||
message_lineno = token.lineno | message_lineno = token.lineno | ||||
call_stack += 1 | call_stack += 1 | ||||
elif call_stack == -1 and token.type == 'linecomment': | elif call_stack == -1 and token.type == 'linecomment': | ||||
value = token.value[2:].strip() | value = token.value[2:].strip() | ||||
if translator_comments and \ | if translator_comments and \ | ||||
translator_comments[-1][0] == token.lineno - 1: | translator_comments[-1][0] == token.lineno - 1: | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | def extractJavascriptFromFile(self, fileObject): | ||||
messages.append(last_argument) | messages.append(last_argument) | ||||
last_argument = None | last_argument = None | ||||
else: | else: | ||||
messages.append(None) | messages.append(None) | ||||
concatenate_next = False | concatenate_next = False | ||||
elif token.value == '+': | elif token.value == '+': | ||||
concatenate_next = True | concatenate_next = True | ||||
elif call_stack > 0 and token.type == 'operator' \ | elif call_stack > 0 and token.type == 'operator' and \ | ||||
and token.value == ')': | (token.value == ')' or token.value == ']' or token.value == '}'): | ||||
call_stack -= 1 | call_stack -= 1 | ||||
elif funcname and call_stack == -1: | elif funcname and call_stack == -1: | ||||
funcname = None | funcname = None | ||||
elif call_stack == -1 and token.type == 'name' and \ | elif call_stack == -1 and token.type == 'name' and \ | ||||
token.value in keywords and \ | token.value in keywords and \ | ||||
(last_token is None or last_token.type != 'name' or | (last_token is None or last_token.type != 'name' or | ||||
▲ Show 20 Lines • Show All 267 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator