def GetPlaceholderLabel(self, englishText, **kwargs): tags = _Tokenize(englishText) parsedText = eveLocalization.Parse(englishText, locconst.LOCALE_SHORT_ENGLISH, tags, **kwargs) LogWarn('Placeholder label (%s) needs to be replaced.' % englishText) return '!_%s_!' % parsedText
def ValidateString(sourceText, languageID, dummyData=None): import localization if dummyData is None: dummyData = { eveLocalization.VARIABLE_TYPE.CHARACTER: 1, eveLocalization.VARIABLE_TYPE.NPCORGANIZATION: 1, eveLocalization.VARIABLE_TYPE.ITEM: 1, eveLocalization.VARIABLE_TYPE.LOCATION: 1, eveLocalization.VARIABLE_TYPE.CHARACTERLIST: [1], eveLocalization.VARIABLE_TYPE.MESSAGE: 1, eveLocalization.VARIABLE_TYPE.DATETIME: blue.os.GetWallclockTime(), eveLocalization.VARIABLE_TYPE.FORMATTEDTIME: blue.os.GetWallclockTime(), eveLocalization.VARIABLE_TYPE.TIMEINTERVAL: const.SEC, eveLocalization.VARIABLE_TYPE.NUMERIC: 99.9, eveLocalization.VARIABLE_TYPE.GENERIC: 'This is a test message.' } errors = [] oldMethod = localization.LogError def ValidationLogError(*args): oldMethod(*args) errors.append(args) localization.LogError = ValidationLogError openCount = sourceText.count('{') closeCount = sourceText.count('}') if openCount != closeCount: return ["Mismatching brackets in string '" + unicode(sourceText) + "'"] try: tags = localization._Tokenize(sourceText) except Exception as e: return [ "Exception occurred when attempting to tokenize string '" + unicode(sourceText) + "': " + repr(e) ] kwargs = {} for tag in tags.values(): if tag['variableName'] and tag['variableType'] in dummyData: kwargs[tag['variableName']] = dummyData[tag['variableType']] if 'linkinfo' in tag['kwargs']: kwargs[tag['kwargs']['linkinfo']] = ('showinfo', 1) if 'quantity' in tag['kwargs']: kwargs[tag['kwargs']['quantity']] = 3 result = sourceText try: result = eveLocalization.Parse(sourceText, languageID, tags, **kwargs) except Exception as e: errors = [ "Exception occurred when attempting to validate string '" + unicode(sourceText) + "': " + repr(e) + repr(kwargs) ] localization.LogError = oldMethod if errors: return errors return result
def ValidateString(sourceText, languageID, dummyData=None): """ Validates a string for tokenizer and parser errors. Returns a list of error messages, if any are found for the given string. """ if dummyData is None: dummyData = GetDummyData() errors = [] oldMethod = locLogger.LogError def ValidationLogError(*args): oldMethod(*args) errors.append(args) locLogger.LogError = ValidationLogError openCount = sourceText.count('{') closeCount = sourceText.count('}') if openCount != closeCount: return ["Mismatching brackets in string '" + unicode(sourceText) + "'"] try: tags = _Tokenize(sourceText) except Exception as e: return [ "Exception occurred when attempting to tokenize string '" + unicode(sourceText) + "': " + repr(e) ] kwargs = {} for tag in tags.values(): if tag['variableName'] and tag['variableType'] in dummyData: kwargs[tag['variableName']] = dummyData[tag['variableType']] if 'linkinfo' in tag['kwargs']: kwargs[tag['kwargs']['linkinfo']] = ('showinfo', 1) if 'quantity' in tag['kwargs']: kwargs[tag['kwargs']['quantity']] = 3 result = sourceText try: result = eveLocalization.Parse(sourceText, languageID, tags, **kwargs) except Exception as e: errors = [ "Exception occurred when attempting to validate string '" + unicode(sourceText) + "': " + repr(e) + repr(kwargs) ] locLogger.LogError = oldMethod if errors: return errors return result
def GetPlaceholderLabel(self, englishText, **kwargs): """ Method to temporary display all hardcoded strings. The method will log a warning reminding to remove the hardcoded string from the code when done. Placeholders are expected to be in English, so that markup tags that are language-sensitive will render properly if the client is not in English. parameters: englishText - the english hardcoded string **kwargs - variable definitions for dynamic text """ tags = _Tokenize(englishText) parsedText = eveLocalization.Parse(englishText, locconst.LOCALE_SHORT_ENGLISH, tags, **kwargs) LogWarn('Placeholder label (%s) needs to be replaced.' % englishText) return '!_%s_!' % parsedText