def run_validation(self, value): if isinstance(value, str): value = [value] elif not isinstance(value, (list, tuple)): raise config_options.ValidationError( 'Expected a list of language codes.') for lang in value: if lang != 'en' and not self.lang_file_exists(lang): raise config_options.ValidationError( '"{}" is not a supported language code.'.format(lang)) return value
def validate_config(self, config): """ Given a config with values for site_dir and doc_dir, run site_dir post_validation. """ site_dir = config_options.SiteDir() docs_dir = config_options.Dir() fname = os.path.join(os.path.abspath('..'), 'mkdocs.yml') config['docs_dir'] = docs_dir.validate(config['docs_dir']) config['site_dir'] = site_dir.validate(config['site_dir']) schema = [ ('site_dir', site_dir), ('docs_dir', docs_dir), ] cfg = Config(schema, fname) cfg.load_dict(config) failed, warned = cfg.validate() if failed: raise config_options.ValidationError(failed) return True
def run_validation(self, value): if isinstance(value, str): value = [value] elif not isinstance(value, (list, tuple)): raise config_options.ValidationError( 'Expected a list of language codes.') for lang in list(value): if lang != 'en': lang_detected = self.get_lunr_supported_lang(lang) if not lang_detected: log.info( f"Option search.lang '{lang}' is not supported, falling back to 'en'" ) value.remove(lang) if 'en' not in value: value.append('en') elif lang_detected != lang: value.remove(lang) value.append(lang_detected) log.info( f"Option search.lang '{lang}' switched to '{lang_detected}'" ) return value