def __init__(self, lang, reference_dir, localization_dir): self.fluent_parser = FluentParser(with_spans=False) self.fluent_serializer = FluentSerializer() # An iterable of plural category names relevant to the context's # language. E.g. ('one', 'other') for English. try: self.plural_categories = get_plural_categories(lang) except RuntimeError as e: logging.getLogger('migrate').warn(e) self.plural_categories = get_plural_categories('en') # Paths to directories with input data, relative to CWD. self.reference_dir = reference_dir self.localization_dir = localization_dir # Parsed input resources stored by resource path. self.reference_resources = {} self.localization_resources = {} # An iterable of `FTL.Message` objects some of whose nodes can be the # transform operations. self.transforms = {} # A dict whose keys are `(path, key)` tuples corresponding to target # FTL translations, and values are sets of `(path, key)` tuples # corresponding to localized entities which will be migrated. self.dependencies = {}
def __init__(self, lang, reference_dir, localization_dir): self.fluent_parser = FluentParser(with_spans=False) self.fluent_serializer = FluentSerializer() # An iterable of plural category names relevant to the context's # language. E.g. ('one', 'other') for English. try: self.plural_categories = CATEGORIES_BY_LOCALE[lang] except KeyError as locale_key: logger = logging.getLogger('migrate') logger.warning('Plural rule for "{}" is not defined in ' 'compare-locales'.format(locale_key)) self.plural_categories = ('one', 'other') # Paths to directories with input data, relative to CWD. self.reference_dir = reference_dir self.localization_dir = localization_dir # Parsed input resources stored by resource path. self.reference_resources = {} self.localization_resources = {} self.target_resources = {} # An iterable of `FTL.Message` objects some of whose nodes can be the # transform operations. self.transforms = {} # A dict whose keys are `(path, key)` tuples corresponding to target # FTL translations, and values are sets of `(path, key)` tuples # corresponding to localized entities which will be migrated. self.dependencies = {}
def __init__( self, lang, reference_dir, localization_dir, enforce_translated=False ): self.fluent_parser = FluentParser(with_spans=False) self.fluent_serializer = FluentSerializer() # An iterable of plural category names relevant to the context's # language. E.g. ('one', 'other') for English. self.plural_categories = get_plural(lang) if self.plural_categories is None: logger = logging.getLogger('migrate') logger.warning( 'Plural rule for "{}" is not defined in ' 'compare-locales'.format(lang)) self.plural_categories = ('one', 'other') self.enforce_translated = enforce_translated # Parsed input resources stored by resource path. self.reference_resources = {} self.localization_resources = {} self.target_resources = {} # An iterable of `FTL.Message` objects some of whose nodes can be the # transform operations. self.transforms = {} # The evaluator instance is an AST transformer capable of walking an # AST hierarchy and evaluating nodes which are migration Transforms. self.evaluator = Evaluator(self)
def build_ftl(messages, dtd, data): res = ast.Resource() for id_str in messages: msg = messages[id_str] l10n_id = ast.Identifier(id_str) val = None attrs = [] if msg['value']: dtd_val = get_value_from_dtd(msg['value'], dtd) val = ast.Pattern([ast.TextElement(dtd_val)]) for attr_name in msg['attrs']: dtd_val = get_value_from_dtd(msg['attrs'][attr_name], dtd) attr_val = ast.Pattern([ast.TextElement(dtd_val)]) attrs.append(ast.Attribute(ast.Identifier(attr_name), attr_val)) m = ast.Message(l10n_id, val, attrs) res.body.append(m) serializer = FluentSerializer() return serializer.serialize(res)
def setUp(self): self.serializer = FluentSerializer()
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 ######################################## Var definitions ############################################################### logging.basicConfig(level=logging.INFO) project = Project() serializer = FluentSerializer() parser = FluentParser() formatter = FluentFormatter() yaml_files_paths = project.get_files_paths_by_dir(project.prototypes_dir_path, 'yml') yaml_files = list( map(lambda yaml_file_path: YAMLFile(yaml_file_path), yaml_files_paths)) ######################################################################################################################## logging.info(f'Поиск yaml-файлов ...') YAMLExtractor(yaml_files).execute()