27
27
('cross_language_search' , Type (bool , default = True )),
28
28
('min_translated_messages' , Type ((str , int ), default = None )),
29
29
('exclude' , Type (list , default = [])),
30
+ ('translate' , Type (list , default = [])),
30
31
)
31
32
32
33
@@ -183,7 +184,7 @@ def _languages_required():
183
184
# if cross_language_search is active, add all languages to 'search'
184
185
# plugin configuration
185
186
lunr_languages = get_lunr_languages ()
186
- search_langs = config ['plugins' ]['search' ].config [ 'lang' ] or []
187
+ search_langs = config ['plugins' ]['search' ].config . get ( 'lang' , [])
187
188
for language in plugin .config ['languages' ]:
188
189
if language in lunr_languages :
189
190
if language not in search_langs :
@@ -220,7 +221,7 @@ def _languages_required():
220
221
plugin .config ['min_translated_messages' ] = min_translated
221
222
222
223
# check that 'exclude' contains a valid list
223
- exclude = plugin .config .get ('exclude' ) or []
224
+ exclude = plugin .config .get ('exclude' , [])
224
225
if not isinstance (exclude , list ):
225
226
raise ValidationError (
226
227
'Expected mdpo\' s "exclude" setting to be a list, but found'
@@ -236,6 +237,28 @@ def _languages_required():
236
237
)
237
238
plugin .config ['exclude' ] = exclude
238
239
240
+ # translation of configuration settings
241
+ valid_translate_settings = ['site_name' , 'site_description' ]
242
+ for setting in plugin .config .get ('translate' , []):
243
+ if setting not in valid_translate_settings :
244
+ valid_translate_settings_readable = ' and ' .join ([
245
+ f"'{ opt } '" for opt in valid_translate_settings
246
+ ])
247
+ raise ValidationError (
248
+ f"The setting '{ setting } ' is not supported for"
249
+ " 'plugins.mdpo.translate' config setting. Valid settings"
250
+ f' are { valid_translate_settings_readable } ' ,
251
+ )
252
+ elif (
253
+ setting == 'site_description'
254
+ and not config .get ('site_description' )
255
+ ):
256
+ logger .warn (
257
+ '[mdpo] "site_description" is configured to be translated'
258
+ ' but was not defined in mkdocs.yml' ,
259
+ )
260
+ plugin .config ['translate' ].remove ('site_description' )
261
+
239
262
# store reference in plugin to markdown_extensions for later usage
240
263
plugin .extensions .markdown = markdown_extensions
241
264
0 commit comments