Created
September 7, 2012 04:11
-
-
Save navilan/3663059 to your computer and use it in GitHub Desktop.
Locale plugin for multilanguage hyde site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file should be placed in the root directory for french language files | |
# ... | |
language: fr | |
lc: fr_CA | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mode: development | |
# ... | |
plugins: | |
- site_defaults.SiteDefaults | |
- hyde.ext.plugins.meta.MetaPlugin | |
- hyde.ext.plugins.auto_extend.AutoExtendPlugin | |
- hyde.ext.plugins.sorter.SorterPlugin | |
- hyde.ext.plugins.tagger.TaggerPlugin | |
- hyde.ext.plugins.syntext.SyntextPlugin | |
- hyde.ext.plugins.textlinks.TextlinksPlugin | |
- hyde.ext.plugins.urls.UrlCleanerPlugin | |
context: | |
data: | |
# ... | |
languages: | |
fr: Français | |
en: English | |
meta: | |
nodemeta: meta.yaml | |
created: !!timestamp 2012-08-02 14:04:01 | |
encoding: utf-8 | |
lc: 'en_US' | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from hyde.plugin import Plugin | |
from jinja2 import contextfunction, Markup | |
import locale | |
@contextfunction | |
def datetime(context, val, fmt=False): | |
import locale, datetime | |
fmt = fmt if fmt else locale.nl_langinfo(locale.D_T_FMT) | |
result = val.strftime(fmt) | |
return Markup(result.decode('utf-8')) | |
class SiteDefaults(Plugin): | |
def template_loaded(self, template): | |
self.template = template | |
template.env.globals['datetime'] = datetime | |
def begin_text_resource(self, resource, text): | |
if (resource.meta.lc): | |
self.default_locale = locale.getlocale() | |
locale.setlocale(locale.LC_ALL, | |
(resource.meta.lc, resource.meta.encoding)) | |
return text | |
def end_text_resource(self, resource, text): | |
if (resource.meta.lc): | |
locale.setlocale(locale.LC_ALL, self.default_locale) | |
return text | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment