def execute(self): for keys in self.group: full_message = FluentSerializedMessage.from_lokalise_keys( self.group[keys]) parsed_message = FluentParser().parse(full_message) ru_full_path = self.group[keys][0].get_file_path().ru ru_file = FluentFile(ru_full_path) try: ru_file_parsed = ru_file.read_parsed_data() except: logging.error(f'Файла {ru_file.full_path} не существует') continue manager = LokaliseFluentAstComparerManager( sourse_parsed=ru_file_parsed, target_parsed=parsed_message) for_update = manager.for_update() for_create = manager.for_create() for_delete = manager.for_delete() if len(for_update): updated_ru_file_parsed = manager.update(for_update) updated_ru_file_serialized = FluentSerializer( with_junk=True).serialize(updated_ru_file_parsed) ru_file.save_data(updated_ru_file_serialized) updated_keys = list( map(lambda el: el.get_id_name(), for_update)) logging.info( f'Обновлены ключи: {updated_keys} в файле {ru_file.full_path}' )
def create_ru_analog(self, en_relative_file: RelativeFile) -> FluentFile: en_file: FluentFile = en_relative_file.file en_file_data = en_file.read_data() ru_file_path = en_file.full_path.replace('en-US', 'ru-RU') ru_file = FluentFile(ru_file_path) ru_file.save_data(en_file_data) logging.info( f'Создан файл {ru_file_path} с переводами из английского файла') return ru_file
def create_en_fluent_file(self, relative_parent_dir, file_name, file_data): en_new_dir_path = os.path.join(project.en_locale_prototypes_dir_path, relative_parent_dir) en_fluent_file = FluentFile( os.path.join(en_new_dir_path, f'{file_name}.ftl')) en_fluent_file.save_data(file_data) logging.info( f'Актуализирован файл английской локали {en_fluent_file.full_path}' ) return en_fluent_file.full_path
def get_relative_path_dict(self, file: FluentFile, locale): if locale == 'ru-RU': return RelativeFile( file=file, locale=locale, relative_path_from_locale=file.get_relative_path( self.project.ru_locale_dir_path)) elif locale == 'en-US': return RelativeFile( file=file, locale=locale, relative_path_from_locale=file.get_relative_path( self.project.en_locale_dir_path)) else: raise Exception(f'Локаль {locale} не поддерживается')
def get_fluent_files_by_dir(self, dir_path): files = [] files_paths_list = glob.glob(f'{dir_path}/**/*.ftl', recursive=True) for file_path in files_paths_list: try: files.append(FluentFile(file_path)) except: continue return files
def create_ru_fluent_file(self, en_analog_file_path): ru_file_full_path = en_analog_file_path.replace('en-US', 'ru-RU') if os.path.isfile(ru_file_full_path): return else: en_file = FluentFile(f'{en_analog_file_path}') file = FluentFile(f'{ru_file_full_path}') file.save_data(en_file.read_data()) logging.info(f'Создан файл русской локали {ru_file_full_path}') return ru_file_full_path
def get_file_pair( self, en_file: FluentFile) -> typing.Tuple[FluentFile, FluentFile]: ru_file_path = en_file.full_path.replace('en-US', 'ru-RU') ru_file = FluentFile(ru_file_path) return en_file, ru_file