diff --git a/docs/settings.rst b/docs/settings.rst index 5775edf1..ddc41681 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -39,7 +39,10 @@ Setting name (default value) what does it do? `JINJA_EXTENSIONS` (``[]``) A list of any Jinja2 extensions you want to use. `DELETE_OUTPUT_DIRECTORY` (``False``) Delete the output directory and just the generated files. -`LOCALE` (''[1]_) Change the locale. +`LOCALE` (''[1]_) Change the locale. A list of locales can be provided + here or a single string representing one locale. + When providing a list, all the locales will be tried + until one works. `MARKUP` (``('rst', 'md')``) A list of available markup languages you want to use. For the moment, only available values are `rst` and `md`. diff --git a/pelican/settings.py b/pelican/settings.py index 55577d84..e5afa63d 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -53,6 +53,19 @@ def read_settings(filename): if key.isupper(): context[key] = tempdict[key] + # if locales is not a list, make it one + locales = context['LOCALE'] + + if type(locales) is str: + locales = [str] + + # try to set the different locales, fallback on the default. + for locale_ in context['LOCALE']: + try: + locale.setlocale(locale.LC_ALL, locale_) + break # break if it is successfull + except locale.Error: + pass + # set the locale - locale.setlocale(locale.LC_ALL, context['LOCALE']) return context