1
0
Fork 0
forked from github/pelican

Add the possibility to specify a list of alternatives for locales. Fixes #115

This commit is contained in:
Alexis Metaireau 2011-05-19 17:28:45 +01:00
commit 5277b9dc16
2 changed files with 18 additions and 2 deletions

View file

@ -39,7 +39,10 @@ Setting name (default value) what does it do?
`JINJA_EXTENSIONS` (``[]``) A list of any Jinja2 extensions you want to use. `JINJA_EXTENSIONS` (``[]``) A list of any Jinja2 extensions you want to use.
`DELETE_OUTPUT_DIRECTORY` (``False``) Delete the output directory and just `DELETE_OUTPUT_DIRECTORY` (``False``) Delete the output directory and just
the generated files. 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 `MARKUP` (``('rst', 'md')``) A list of available markup languages you want
to use. For the moment, only available values to use. For the moment, only available values
are `rst` and `md`. are `rst` and `md`.

View file

@ -53,6 +53,19 @@ def read_settings(filename):
if key.isupper(): if key.isupper():
context[key] = tempdict[key] 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 # set the locale
locale.setlocale(locale.LC_ALL, context['LOCALE'])
return context return context