def pointer_red(self): self.NextStringButton.setEnabled(True) self.user_text[self.pointer] = check_new_line_sym_ending( self.EditString.toPlainText()) self.pointer -= 1 self.check_new_line_symbol_string(False) if self.pointer < 0: self.pointer = 0 self.check_new_line_symbol_string(True) self.PreviousStringButton.setEnabled(False) self.set_lines()
def set_lines(self): self.OriginalString.setText(self.orig_text[self.pointer]) self.machine_text[self.pointer] = check_new_line_sym_ending( translate_line(self.orig_text[self.pointer], self.file.type)) if self.machine_text[self.pointer] == '\n' \ else self.machine_text[self.pointer] self.TranslateString.setText(self.machine_text[self.pointer]) self.EditString.setText(self.user_text[self.pointer] if self.user_text[ self.pointer] != '\n' else self.machine_text[self.pointer]) self.centering_lines() self.StringOrder.setText(f'{self.pointer + 1}') self.progressbar_set_value()
def strings_parsing(source_file_path, original_file_path, file_type): source_text = [] with open(original_file_path, 'r', encoding='utf-8') as original_text,\ open(source_file_path, 'w', encoding='utf-8') as source: original_text = original_text.readlines() for line in original_text: if search_for_nesessary(file_type, line) and search_for_unnesessary( file_type, line): symbol = '\t' if '\t' in line else line.find('"') if type(symbol) is not int: prepared_line = line.split(symbol)[-1] if prepared_line[0].islower(): # Если первая буква строки не является заглавной, # то есть перед необходимым текстом имеются ненужные элементы quote_symbol = line.find('\"') - 1 # Если в строке есть '"', # то делаем срез от начала кавычки до конца строки letter_symbol = line.find('=') + 2 # Если в строке нет кавычки, но есть '=', # если первая буква после '=' является заглавной, # то делаем срез от начала первой буквы до конца строки prepared_line = line[quote_symbol:] if '\"' in line \ else line[letter_symbol if line[letter_symbol].isupper() else -1:] # В противном случае оставляем только '\n' else: prepared_line = line[symbol:] if '_' not in prepared_line: for part in separate_unnecessary_parts( prepared_line.lstrip(), file_type): part = check_new_line_sym_ending(part) source_text.append(part) else: source_text.append('\n') else: source_text.append('\n') return original_text, source_text
def save_localisation(self): self.user_text[self.pointer] = check_new_line_sym_ending( self.EditString.toPlainText()) try: self.file.tr_status = round((self.bar[0].value() / self.bar[0].maximum()) * 100) \ if self.bar[0].value() != self.bar[0].maximum() \ else 100 # meaning it's Complete self.file.pointer_pos = self.pointer collection_update(self.file, self.machine_text, self.user_text) message = 'file_was_updated' call_success_message(self, message) if self.file.tr_status == 100: put_lines(self.file) pop_stack() self.clean_state() except AttributeError: message = 'no_translation' call_error_message(self, message)