Changes about locales and dates.

Add a way to specify the locale in the settings, and the date formating as well.
Fixes #61.
This commit is contained in:
Alexis Metaireau 2011-02-01 21:44:50 +00:00
commit d13e6f14fb
16 changed files with 39 additions and 13 deletions

View file

@ -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`.

View file

@ -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')

View file

@ -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

View file

@ -6,7 +6,7 @@
<dl>
<h2 class="title">Archives de {{ SITENAME }}</h2>
{% for article in dates %}
<dt>{{ article.date.strftime('%a %d %B %Y') }}</dt>
<dt>{{ article.locale_date }}</dt>
<dd><a href='{{ article.url }}'>{{ article.title }}</a></dd>
<dd>Catégorie : <a href="{{ article.category }}">{{ article.category }}</a></dd>
{% endfor %}

View file

@ -4,7 +4,7 @@
<div id="content">
<div class="post">
<h2 class="title"><a href="{{ article.url }}">{{ article.title }}</a></h2>
<p class="meta"><span class="date">Le {{ article.date.strftime('%a %d %B %Y') }} </span><span class="posted">Par <a href="#">{{ article.author }}</a></span><span>&nbsp; | Catégorie : <a href="{{ SITEURL }}/category/{{ article.category }}.html">{{ article.category }}</a></span></p>
<p class="meta"><span class="date">Le {{ article.locale_date }} </span><span class="posted">Par <a href="#">{{ article.author }}</a></span><span>&nbsp; | Catégorie : <a href="{{ SITEURL }}/category/{{ article.category }}.html">{{ article.category }}</a></span></p>
<p class="meta">Tags : {% for tag in article.tags %}
<span><a href="{{ SITEURL }}/tag/{{ tag }}.html">{{ tag }}</a> / </span>
{% endfor %}</p>

View file

@ -7,7 +7,7 @@
<div id="content">
<div class="post">
<h2 class="title"><a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a></h2>
<p class="meta"><span class="date">Le {{ article.date.strftime('%a %d %B %Y') }} </span><span class="posted">Par <a href="#">{{ article.author }}</a></span><span>&nbsp; | Catégorie : <a href="{{ SITEURL }}/category/{{ article.category }}.html">{{ article.category }}</a></span></p>
<p class="meta"><span class="date">Le {{ article.date.locale_date }} </span><span class="posted">Par <a href="#">{{ article.author }}</a></span><span>&nbsp; | Catégorie : <a href="{{ SITEURL }}/category/{{ article.category }}.html">{{ article.category }}</a></span></p>
<p class="meta">Tags : {% for tag in article.tags %}
<span><a href="{{ SITEURL }}/tag/{{ tag }}.html">{{ tag }}</a> / </span>
{% endfor %}</p>
@ -25,7 +25,7 @@
{% else %}
<div class="post summary">
<h2 class="title"><a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a></h2>
<p class="meta"><span class="date">Le {{ article.date.strftime('%a %d %B %Y') }}</span><span class="posted">Par <a href="#">{{ article.author }}</a></span></p>
<p class="meta"><span class="date">Le {{ article.locale_date }}</span><span class="posted">Par <a href="#">{{ article.author }}</a></span></p>
<div style="clear: both;">&nbsp;</div>
<div class="entry">
{{ article.summary }}

View file

@ -6,7 +6,7 @@
{% if article.author %}
By <a class="url fn" href="#">{{ article.author }}</a>
{% endif %}
on <a>{{ article.date.strftime('%a %d %B %Y') }}</a>
on <a>{{ article.date.locale_date }}</a>
about <a href="{{ SITEURL }}/category/{{ article.category }}.html">{{ article.category }}</a>
</div>
{{ article.content }}

View file

@ -4,6 +4,6 @@
<div class="info"></div>
{% for article in articles %}
<h2><a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a></h2>
<p class="published">{{ article.date.strftime('%a %d %B %Y') }}</p>
<p class="published">{{ article.locale_date }}</p>
{{ article.summary }}
{% endfor %}

View file

@ -4,7 +4,7 @@
{% if SITESUBTITLE %} <div class="info">{{ SITESUBTITLE }}</div> {% endif %}
{% for article in articles %}
<h2><a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a></h2>
<p class="published">{{ article.date.strftime('%a %d %B %Y') }}</p>
<p class="published">{{ article.locale_date }}</p>
{{ article.summary }}
{% endfor %}
{% endblock %}

View file

@ -5,7 +5,7 @@
<dl>
{% for article in dates %}
<dt>{{ article.date.strftime('%a %d %B %Y') }}</dt>
<dt>{{ article.locale_date }}</dt>
<dd><a href='{{ article.url }}'>{{ article.title }}</a></dd>
{% endfor %}
</dl>

View file

@ -1,6 +1,6 @@
<footer class="post-info">
<abbr class="published" title="{{ article.date.isoformat() }}">
{{ article.date.strftime('%a %d %B %Y') }}
{{ article.locale_date }}
</abbr>
{% if article.author %}

View file

@ -4,7 +4,7 @@
<dl>
{% for article in dates %}
<dt>{{ article.date.strftime('%Y-%m-%d %H:%M') }}</dt>
<dt>{{ article.locale_date }}</dt>
<dd><a href='{{ article.url }}'>{{ article.title }}</a></dd>
{% endfor %}
</dl>

View file

@ -4,7 +4,7 @@
<header> <h2 class="entry-title"><a href="{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title}}">{{ article.title }}</a></h2> </header>
<footer class="post-info">
<abbr class="published" title="{{ article.date.isoformat() }}">
{{ article.date.strftime('%Y-%m-%d %H:%M') }}
{{ article.locale_date }}
</abbr>
{% if article.author %}
<address class="vcard author">

View file

@ -10,7 +10,7 @@
<li><article class="hentry">
<header> <h2 class="entry-title"><a href="{{ article.url }}" rel="bookmark" title="Permalink to {{ article.title}}">{{ article.title }}</a></h2> </header>
<footer class="post-info">
<abbr class="published" title="{{ article.date.isoformat() }}"> {{ article.date.strftime('%Y-%m-%d %H:%M') }} </abbr>
<abbr class="published" title="{{ article.date.isoformat() }}"> {{ article.locale_date }} </abbr>
{% if article.author %}<address class="vcard author">By <a class="url fn" href="#">{{ article.author }}</a></address>{% endif %}
</footer><!-- /.post-info -->
<div class="entry-content"> {{ article.summary }} </div><!-- /.entry-content -->

View file

@ -115,7 +115,7 @@ class Writer(object):
context[i] = self.update_context_contents(name, context[i])
elif type(context[i]) == dict:
context[i] = self.update_context_content(name, context[i].values())
context[i] = self.update_context_contents(name, context[i].values())
elif hasattr(context[i], '_content'):
relative_path = get_relative_path(name)

View file

@ -7,6 +7,7 @@ GITHUB_URL = 'http://github.com/ametaireau/'
DISQUS_SITENAME = "blog-notmyidea"
PDF_GENERATOR = False
REVERSE_CATEGORY_ORDER = True
LOCALE = 'en_US.utf8'
LINKS = (('Biologeek', 'http://biologeek.org'),
('Filyb', "http://filyb.info/"),