예제 #1
0
파일: pods.py 프로젝트: uxder/grow
 def get_translator(self, service=utils.SENTINEL):
     if 'translators' not in self.yaml:
         return None
     if ('services' not in self.yaml['translators']
             or not self.yaml['translators']['services']):
         return None
     translator_config = self.yaml['translators']
     translators.register_extensions(
         self.yaml.get('extensions', {}).get('translators', []),
         self.root,
     )
     translator_services = copy.deepcopy(translator_config['services'])
     if service is not utils.SENTINEL:
         valid_service_kinds = [each['service']
                                for each in translator_services]
         if not valid_service_kinds:
             text = 'Missing required "service" field in translator config.'
             raise ValueError(text)
         if service not in valid_service_kinds and service is not None:
             text = 'No translator service "{}". Valid services: {}.'
             keys = ', '.join(valid_service_kinds)
             raise ValueError(text.format(service, keys))
     else:
         # Use the first configured translator by default.
         translator_services = translator_services[:1]
     for service_config in translator_services:
         if service_config.get('service') == service or len(translator_services) == 1:
             translator_kind = service_config.pop('service')
             return translators.create_translator(
                 self, translator_kind, service_config,
                 project_title=translator_config.get('project_title'),
                 instructions=translator_config.get('instructions'))
     raise ValueError('No translator service found: {}'.format(service))
예제 #2
0
파일: pods.py 프로젝트: cdhermann/grow
    def get_translator(self, service=utils.SENTINEL):
        if 'translators' not in self.yaml:
            return None
        if ('services' not in self.yaml['translators']
                or not self.yaml['translators']['services']):
            return None
        translator_config = self.yaml['translators']
        translator_extensions = self.yaml.get('extensions',
                                              {}).get('translators', [])
        translators.register_extensions(
            translator_extensions,
            self.root,
        )

        # TODO: Show deprecation message in the future.
        # if translator_extensions:
        #     legacy_message = 'Legacy translators are deprecated and will be removed in the future: {}'
        #     self.deprecated(
        #         'legacy_translator',
        #         legacy_message.format(', '.join(translator_extensions)),
        #         url='https://grow.dev/migration/1.0.0')

        translator_services = copy.deepcopy(translator_config['services'])
        if service is not utils.SENTINEL:
            valid_service_kinds = [
                each['service'] for each in translator_services
            ]
            if not valid_service_kinds:
                text = 'Missing required "service" field in translator config.'
                raise ValueError(text)
            if service not in valid_service_kinds and service is not None:
                text = 'No translator service "{}". Valid services: {}.'
                keys = ', '.join(valid_service_kinds)
                raise ValueError(text.format(service, keys))
        else:
            # Use the first configured translator by default.
            translator_services = translator_services[:1]
        for service_config in translator_services:
            if service_config.get('service') == service or len(
                    translator_services) == 1:
                translator_kind = service_config.pop('service')
                return translators.create_translator(
                    self,
                    translator_kind,
                    service_config,
                    project_title=translator_config.get('project_title'),
                    instructions=translator_config.get('instructions'))
        raise ValueError('No translator service found: {}'.format(service))
예제 #3
0
파일: pods.py 프로젝트: grow/grow
 def get_translator(self, service=utils.SENTINEL):
     if 'translators' not in self.yaml:
         return None
     if ('services' not in self.yaml['translators']
             or not self.yaml['translators']['services']):
         return None
     translator_config = self.yaml['translators']
     inject_name = translator_config.get('inject')
     translators.register_extensions(
         self.yaml.get('extensions', {}).get('translators', []),
         self.root,
     )
     translator_services = copy.deepcopy(translator_config['services'])
     if service is not utils.SENTINEL:
         valid_service_kinds = [each['service']
                                for each in translator_services]
         if not valid_service_kinds:
             text = 'Missing required "service" field in translator config.'
             raise ValueError(text)
         if service not in valid_service_kinds and service is not None:
             text = 'No translator service "{}". Valid services: {}.'
             keys = ', '.join(valid_service_kinds)
             raise ValueError(text.format(service, keys))
     else:
         # Use the first configured translator by default.
         translator_services = translator_services[:1]
     for service_config in translator_services:
         if service_config.get('service') == service or len(translator_services) == 1:
             translator_kind = service_config.pop('service')
             inject = inject_name == translator_kind
             return translators.create_translator(
                 self, translator_kind, service_config,
                 inject=inject,
                 project_title=translator_config.get('project_title'),
                 instructions=translator_config.get('instructions'))
     raise ValueError('No translator service found: {}'.format(service))