def add_to_lookup(self, org_key, org_value): key = org_key value = org_value.strip() if JapaneseLanguage.is_CJKword(org_key) is True: key = key.strip() if key in self._pairs_jp: YLogger.error(self, "%s = %s already exists in jp_collection", key, value) return else: matchs = self._match_jp splits = key check_key = key[0] self._pairs_jp[key] = value else: if key[0] != ' ': key = key.strip() pattern_text = DoubleStringPatternSplitCollection.normalise_pattern( key) start = pattern_text.lstrip() middle = pattern_text end = pattern_text.rstrip() pattern = "(^%s|%s|%s$)" % (start, middle, end) replacement = value replaceInfo = [key, re.compile(pattern), replacement] self._replace.append(replaceInfo) return else: key = key.strip() if key in self._pairs: YLogger.error(self, "%s = %s already exists in en_collection", key, value) return else: matchs = self._match splits = key.split() check_key = splits[0] self._pairs[key] = value if check_key not in matchs: matchs[check_key] = [] matchs[check_key].append(splits)
def add_to_lookup(self, org_key, org_value, filename=None, line=0): key = org_key value = org_value.strip() if key.strip() == '': error_info = "key is empty" self.set_error_info(filename, line, error_info) return if JapaneseLanguage.is_CJKword(org_key) is True: key = key.strip() if key in self._pairs_jp: YLogger.error(self, "%s = %s already exists in jp_collection", key, value) error_info = "duplicate key='%s' (value='%s' is invalid)" % ( key, value) self.set_error_info(filename, line, error_info) return else: matchs = self._match_jp splits = key check_key = key[0] self._pairs_jp[key] = value else: if key[0] != ' ': key = key.strip() if key in self._replace_key: YLogger.error( self, "%s = %s already exists in replace_collection", key, value) error_info = "duplicate replace_chars='%s' (value='%s' is invalid)" % ( key, value) self.set_error_info(filename, line, error_info) return pattern_text = DoubleStringPatternSplitCollection.normalise_pattern( key) start = pattern_text.lstrip() middle = pattern_text end = pattern_text.rstrip() pattern = "(^%s|%s|%s$)" % (start, middle, end) replacement = value replaceInfo = [key, re.compile(pattern), replacement] self._replace.append(replaceInfo) self._replace_key.append(key) return else: key = key.strip() if key in self._pairs: YLogger.error(self, "%s = %s already exists in en_collection", key, value) error_info = "duplicate key='%s' (value='%s' is invalid)" % ( key, value) self.set_error_info(filename, line, error_info) return else: matchs = self._match splits = key.split() check_key = splits[0] self._pairs[key] = value if check_key not in matchs: matchs[check_key] = [] matchs[check_key].append(splits)