def IsValidTypeAndProperty(self, typeName, propertyName, languageID=None): IS_INVALID_TYPE = 0 IS_INVALID_PROPERTY = 1 IS_VALID_TYPE_AND_PROPERTY = 2 result = None languageID = localizationInternalUtil.StandardizeLanguageID( languageID) or localizationUtil.GetLanguageID() foundType = self.languageTypesWithProperties.get(typeName, None) if foundType is not None: foundPropertyList = foundType.get(languageID, None) if foundPropertyList is not None: if propertyName in foundPropertyList: result = IS_VALID_TYPE_AND_PROPERTY else: result = IS_INVALID_PROPERTY else: result = IS_INVALID_PROPERTY else: result = IS_INVALID_TYPE if result == IS_INVALID_PROPERTY: LogError( "'%s' is not a valid property for '%s' in language '%s'." % (propertyName, typeName, languageID)) elif result == IS_INVALID_TYPE: LogError( "'%s' is not a valid type; cannot retrieve properties for it." % typeName) elif result is None: LogError( 'IsValidTypeAndProperty wasnt able to determine if type and property were valid: %s, %s' % (typeName, propertyName)) return result == IS_VALID_TYPE_AND_PROPERTY
def IsSearchTextIdeographic(languageID, textString): languageID = localizationInternalUtil.StandardizeLanguageID(languageID) if languageID in (localization.LOCALE_SHORT_JAPANESE, localization.LOCALE_SHORT_CHINESE): try: textString.encode('ascii') except UnicodeEncodeError: return True return False
def FormatGenericList(iterable, languageID=None): if languageID is not None: languageID = localizationInternalUtil.StandardizeLanguageID(languageID) if languageID is None: languageID = GetLanguageID() delimiterDict = {'en-us': u', ', 'ja': u'\u3001', 'zh-cn': u'\uff0c'} stringList = [unicode(each) for each in iterable] delimeter = delimiterDict.get(languageID, delimiterDict['en-us']) return localizationInternalUtil.PrepareLocalizationSafeString( delimeter.join(stringList), messageID='genericlist')
def GetMetaData(self, messageID, propertyName, languageID=None): languageID = localizationInternalUtil.StandardizeLanguageID( languageID) or localizationUtil.GetLanguageID() propertyString = self._GetMetaData(messageID, propertyName, languageID) if propertyString is not None: return localizationInternalUtil.PrepareLocalizationSafeString( propertyString, messageID=messageID) LogError( 'a non existent property was requested. messageID,propertyName,languageID : %s,%s,%s' % (messageID, propertyName, languageID)) return '[no property:%s,%s]' % (messageID, propertyName)
def LoadSecondaryLanguageForClient(self, languageID): if boot.role != 'client': return False languageID = localizationInternalUtil.StandardizeLanguageID(languageID) if languageID == self._primaryLanguageID: self._secondaryLanguageID = None return True self._secondaryLanguageID = languageID if self._secondaryLanguageID in self.languagesDefined: if not self._LoadLanguagePickle(self.CLIENT_PREFIX, self._secondaryLanguageID): return False else: LogError("Language '", languageID, "' is not enabled. Text data was not loaded.") return False return True
def LoadPrimaryLanguage(self, prefix, languageID=None, importantOnly=False): if languageID is None: languageID = self._GetPrimaryLanguage() languageID = localizationInternalUtil.StandardizeLanguageID(languageID) self._primaryLanguageID = languageID eveLocalization.SetPrimaryLanguage(languageID) if self._primaryLanguageID in self.languagesDefined: if not self._LoadLanguagePickle(prefix, self._primaryLanguageID, importantOnly): return False else: LogError("Language '", languageID, "' is not enabled. Text data was not loaded.") return False return True
def _ReadLocalizationLanguagePickles(self, prefix, supportedLanguages): primaryLanguage = self._GetPrimaryLanguage() if boot.role == 'client': prefsLanguage = localizationInternalUtil.StandardizeLanguageID( prefs.GetValue('languageID', None)) if prefsLanguage != primaryLanguage: if not (self.LoadPrimaryLanguage(prefix, importantOnly=False) and self.LoadSecondaryLanguageForClient(prefsLanguage)): return False else: return self.LoadPrimaryLanguage(prefix) elif boot.role == 'server' or boot.role == 'proxy': if not self.LoadPrimaryLanguage(prefix): return False for aLangCode in supportedLanguages: if aLangCode != self._primaryLanguageID and not self._LoadLanguagePickle( prefix, aLangCode): return False return True
def FormatGenericList(iterable, languageID=None, useConjunction=False): languageID = localizationInternalUtil.StandardizeLanguageID( languageID) or localizationUtil.GetLanguageID() stringList = [unicode(each) for each in iterable] delimiter = localization.GetByLabel( 'UI/Common/Formatting/ListGenericDelimiter') if not useConjunction or len(stringList) < 2: listString = delimiter.join(stringList) elif len(stringList) == 2: listString = localization.GetByLabel( 'UI/Common/Formatting/SimpleGenericConjunction', A=stringList[0], B=stringList[1]) else: listPart = delimiter.join(stringList[:-1]) listString = localization.GetByLabel( 'UI/Common/Formatting/ListGenericConjunction', list=listPart, lastItem=stringList[-1]) return localizationInternalUtil.PrepareLocalizationSafeString( listString, messageID='genericlist')
def Sort(iterable, cmp=None, key=lambda x: x, reverse=False, languageID=None): if cmp: raise ValueError( "Passing a compare function into Sort defeats the purpose of using a language-aware sort. You probably want to use the 'key' parameter instead." ) languageID = languageID or localizationInternalUtil.StandardizeLanguageID( languageID) or GetLanguageID() collator = eveLocalization.Collator() collator.locale = str(languageID) def caseSensitiveSubsort(left, right): if left.lower() == right.lower(): return collator.Compare(unicode(right), unicode(left)) return collator.Compare(unicode(left.lower()), unicode(right.lower())) if all([isinstance(key(each), (int, type(None))) for each in iterable]): def getPronunciation(messageID): if not messageID: return '' ret = '' try: ret = localization.GetMetaData(messageID, 'pronounciation', languageID=languageID) except KeyError: ret = localization.GetByMessageID(messageID, languageID) return ret return sorted(iterable, cmp=caseSensitiveSubsort, key=lambda x: uiutil.StripTags(getPronunciation(key(x))), reverse=reverse) return sorted(iterable, cmp=caseSensitiveSubsort, key=lambda x: uiutil.StripTags(key(x)), reverse=reverse)
def GetByMessageID(self, messageID, languageID=None, **kwargs): if messageID is None: return '' if languageID is not None: languageID = localizationInternalUtil.StandardizeLanguageID( languageID) if languageID is None: languageID = localizationUtil.GetLanguageID() if session and 'player' not in kwargs: kwargs['player'] = session.charid try: textString = self._GetByMessageID(messageID, languageID, **kwargs) return localizationInternalUtil.PrepareLocalizationSafeString( textString, messageID=messageID) except KeyError: log.LogException() return u'[no messageID: %s]' % messageID except: log.LogException() try: return self._GetRawByMessageID(messageID) except: return u'[no messageID: %s]' % messageID
def IsPrimaryLanguage(self, languageID): languageID = localizationInternalUtil.StandardizeLanguageID(languageID) return languageID == self._GetPrimaryLanguage()