diff --git a/docs/settings.rst b/docs/settings.rst index 404b7f68..c1e24671 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -31,7 +31,10 @@ Setting name what it does ? (no rss) `CSS_FILE` To specify the CSS file you want to load, if it's not the default one ('main.css') +`DATE_FORMATS` If you do manage multiple languages, you can set + the date formatting here. `DEFAULT_CATEGORY` The default category to fallback on. `misc` by default. +`DEFAULT_DATE_FORMAT` The default date format you want to use. `DEFAULT_LANG` The default language to use. Default is 'en'. `DISPLAY_PAGES_ON_MENU` Display or not the pages on the menu of the template. Templates can follow or not this settings. @@ -46,6 +49,7 @@ Setting name what it does ? Default is no extensions (the empty list). `KEEP_OUTPUT_DIRECTORY` Keep the output directory and just update all the generated files. +`LOCALE` Change the locale. Default is the system locale. Default is to delete the output directory. `MARKUP` A list of available markup languages you want to use. For the moment, only available values are `rst` and `md`. diff --git a/pelican/contents.py b/pelican/contents.py index b6e71b75..1ace659f 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -47,6 +47,15 @@ class Page(object): if filename: self.filename = filename + if not hasattr(self, 'date_format'): + if self.lang in settings['DATE_FORMATS']: + self.date_format = settings['DATE_FORMATS'][self.lang] + else: + self.date_format = settings['DEFAULT_DATE_FORMAT'] + + # store the settings ref. + self._settings = settings + def check_properties(self): """test that each mandatory property is set.""" for prop in self.mandatory_properties: @@ -65,6 +74,11 @@ class Page(object): def summary(self): return truncate_html_words(self.content, 50) + @property + def locale_date(self): + return self.date.strftime(self.date_format) + + class Article(Page): mandatory_properties = ('title', 'date', 'category') diff --git a/pelican/settings.py b/pelican/settings.py index 3fd0a6da..3070ad15 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -1,4 +1,5 @@ import os +import locale _DEFAULT_THEME = os.sep.join([os.path.dirname(os.path.abspath(__file__)), "themes/notmyidea"]) @@ -24,7 +25,10 @@ _DEFAULT_CONFIG = {'PATH': None, 'RELATIVE_URLS': True, 'DEFAULT_LANG': 'en', 'PELICAN_CLASS': 'pelican.Pelican', + 'DEFAULT_DATE_FORMAT': '%a %d %B %Y', + 'DATE_FORMATS': {}, 'JINJA_EXTENSIONS': [], + 'LOCALE': '', # default to user locale } def read_settings(filename): @@ -37,4 +41,7 @@ def read_settings(filename): for key in tempdict: if key.isupper(): context[key] = tempdict[key] + + # set the locale + locale.setlocale(locale.LC_ALL, context['LOCALE']) return context diff --git a/pelican/themes/brownstone/templates/archives.html b/pelican/themes/brownstone/templates/archives.html index a023ecee..5adaacb6 100644 --- a/pelican/themes/brownstone/templates/archives.html +++ b/pelican/themes/brownstone/templates/archives.html @@ -6,7 +6,7 @@

Archives de {{ SITENAME }}

{% for article in dates %} -
{{ article.date.strftime('%a %d %B %Y') }}
+
{{ article.locale_date }}
{{ article.title }}
Catégorie : {{ article.category }}
{% endfor %} diff --git a/pelican/themes/brownstone/templates/article.html b/pelican/themes/brownstone/templates/article.html index 0467b64c..2458ecb5 100644 --- a/pelican/themes/brownstone/templates/article.html +++ b/pelican/themes/brownstone/templates/article.html @@ -4,7 +4,7 @@

{{ article.title }}

-

Le {{ article.date.strftime('%a %d %B %Y') }} Par {{ article.author }}  | Catégorie : {{ article.category }}

+

Le {{ article.locale_date }} Par {{ article.author }}  | Catégorie : {{ article.category }}

Tags : {% for tag in article.tags %} {{ tag }} / {% endfor %}

diff --git a/pelican/themes/brownstone/templates/index.html b/pelican/themes/brownstone/templates/index.html index 147ea006..3ec17811 100644 --- a/pelican/themes/brownstone/templates/index.html +++ b/pelican/themes/brownstone/templates/index.html @@ -7,7 +7,7 @@

{{ article.title }}

-

Le {{ article.date.strftime('%a %d %B %Y') }} Par {{ article.author }}  | Catégorie : {{ article.category }}

+

Le {{ article.date.locale_date }} Par {{ article.author }}  | Catégorie : {{ article.category }}

Tags : {% for tag in article.tags %} {{ tag }} / {% endfor %}

@@ -25,7 +25,7 @@ {% else %}

{{ article.title }}

-

Le {{ article.date.strftime('%a %d %B %Y') }}Par {{ article.author }}

+

Le {{ article.locale_date }}Par {{ article.author }}

 
{{ article.summary }} diff --git a/pelican/themes/martyalchin/templates/article.html b/pelican/themes/martyalchin/templates/article.html index c7711a75..f5c6591c 100644 --- a/pelican/themes/martyalchin/templates/article.html +++ b/pelican/themes/martyalchin/templates/article.html @@ -6,7 +6,7 @@ {% if article.author %} By {{ article.author }} {% endif %} - on {{ article.date.strftime('%a %d %B %Y') }} + on {{ article.date.locale_date }} about {{ article.category }}
{{ article.content }} diff --git a/pelican/themes/martyalchin/templates/category.html b/pelican/themes/martyalchin/templates/category.html index 8f9b6626..7c72d92a 100644 --- a/pelican/themes/martyalchin/templates/category.html +++ b/pelican/themes/martyalchin/templates/category.html @@ -4,6 +4,6 @@
{% for article in articles %}

{{ article.title }}

-

{{ article.date.strftime('%a %d %B %Y') }}

+

{{ article.locale_date }}

{{ article.summary }} {% endfor %} diff --git a/pelican/themes/martyalchin/templates/index.html b/pelican/themes/martyalchin/templates/index.html index eeaa8a7a..6286ef60 100644 --- a/pelican/themes/martyalchin/templates/index.html +++ b/pelican/themes/martyalchin/templates/index.html @@ -4,7 +4,7 @@ {% if SITESUBTITLE %}
{{ SITESUBTITLE }}
{% endif %} {% for article in articles %}

{{ article.title }}

-

{{ article.date.strftime('%a %d %B %Y') }}

+

{{ article.locale_date }}

{{ article.summary }} {% endfor %} {% endblock %} diff --git a/pelican/themes/notmyidea/templates/archives.html b/pelican/themes/notmyidea/templates/archives.html index 1644affb..5ba2c817 100644 --- a/pelican/themes/notmyidea/templates/archives.html +++ b/pelican/themes/notmyidea/templates/archives.html @@ -5,7 +5,7 @@
{% for article in dates %} -
{{ article.date.strftime('%a %d %B %Y') }}
+
{{ article.locale_date }}
{{ article.title }}
{% endfor %}
diff --git a/pelican/themes/notmyidea/templates/article_infos.html b/pelican/themes/notmyidea/templates/article_infos.html index 818b5277..3a028a1c 100644 --- a/pelican/themes/notmyidea/templates/article_infos.html +++ b/pelican/themes/notmyidea/templates/article_infos.html @@ -1,6 +1,6 @@