How can I change the language of bf.config.blog.archive_links ?

45 views
Skip to first unread message

Christian Specht

unread,
Jan 25, 2013, 1:35:12 PM1/25/13
to blogofil...@googlegroups.com
I'm trying to put a list of months with the number of posts per month into the sidebar my blog.

Right now, I'm doing it this way:

    % for link, name, num_posts in bf.config.blog.archive_links:
    <li><a href="${bf.util.site_path_helper(bf.config.blog.path,link)}/1">${name}&nbsp;(${num_posts})</a></li>
    % endfor
                
...which gives me that:
                
    Mai 2012 (1)
    Februar 2012 (1)
    Mai 2011 (2)
    Juli 2010 (2)
    Juni 2010 (4)

The problem is that the month names are in German.
I'm in Germany and everything on my machine is in German, but I want my site to be in English.

How can I make bf.config.blog.archive_links to return the month names always in English, and not in the language of my machine?

Or is there another way how to get the list of months and the number of posts?
I looked at the code of the "Archive" page.
The months there are returned in English (because I'm setting the locale via import locale and locale.setlocale(locale.LC_ALL, 'english')), but I don't know how to sum up the number of posts per month (it's probably possible in Python, but I don't know Python).


Thanks!
Christian

Christian Specht

unread,
Feb 2, 2013, 2:19:26 PM2/2/13
to blogofil...@googlegroups.com
Okay...I have a solution. It's not the most elegant way, but it works for me:

    % for link, name, num_posts in bf.config.blog.archive_links:
    <%
        if name.startswith('Januar'):
            month=name.replace('Januar','January')
        elif name.startswith('Februar'):
            month=name.replace('Februar','February')
        # omit March because the German name makes Blogofile/Mako crash, because it contains an umlaut
        # (there will never be posts in March anyway, because they make Blogofile/Mako crash, too)
        elif name.startswith('Mai'):
            month=name.replace('Mai','May')
        elif name.startswith('Juni'):
            month=name.replace('Juni','June')
        elif name.startswith('Juli'):
            month=name.replace('Juli','July')
        elif name.startswith('Oktober'):
            month=name.replace('Oktober','October')
        elif name.startswith('Dezember'):
            month=name.replace('Dezember','December')
        else:
            month=name
    %>
    <li><a href="${bf.util.site_path_helper(bf.config.blog.path,link)}/1">${month}&nbsp;(${num_posts})</a></li>
    % endfor

Péter Zsoldos

unread,
Feb 2, 2013, 2:46:00 PM2/2/13
to blogofil...@googlegroups.com

Hi,

Just a quick idea from the top of my head - have you tried setting your shell to the desired locale via the LC_* variables? You could even do that in your .profile (.bashrc, etc.) if you wish

Certainly it would be nice to specify this as a blogofile config variable, but this might be a quick workaround.

Disclaimer - haven't tried it, for being laptopless on the train...

HTH,

Peter

--
You received this message because you are subscribed to the Google Groups "blogofile-discuss" group.
To post to this group, send email to blogofil...@googlegroups.com.
To unsubscribe from this group, send email to blogofile-disc...@googlegroups.com.
Visit this group at http://groups.google.com/group/blogofile-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Christian Specht

unread,
Feb 2, 2013, 3:47:05 PM2/2/13
to blogofil...@googlegroups.com
Hi Peter,

thank you for your answer!
My shell is cmd.exe (Windows) and apparently you can't "just" set another language there:

Christian

Péter Zsoldos

unread,
Feb 2, 2013, 4:21:21 PM2/2/13
to blogofil...@googlegroups.com

Ah, python on windows is rather fun, before using it I thought python was a truly cross platform environment... You could always try cygwin (or git-bash), but then it likely won't be that easy.

I wonder whether the pre_build hook would work here - try adding this to your _config.py file

def pre_build():
    # do the same import & LC_ALL thing here
    # please double check the function name in the docs

This would happen before the posts are rendered to file, and thus setting the locale here would be applied for all your templates

Let us know whether it works!

--
You received this message because you are subscribed to the Google Groups "blogofile-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blogofile-disc...@googlegroups.com.

To post to this group, send email to blogofil...@googlegroups.com.

Christian Specht

unread,
Feb 4, 2013, 6:06:55 PM2/4/13
to blogofil...@googlegroups.com
Hi Peter,

perfect...it works!

The correct syntax looks like this:

def pre_build():
    import locale
    locale.setlocale(locale.LC_ALL, 'english')


Even better, this also solves another issue I had: https://github.com/EnigmaCurry/blogofile/issues/141
Blogofile crashed when I set the date of any blog post to March, probably of the German umlaut (March is the only month which contains an umlaut in German: "März").

By setting the locale to English in the pre_build hook, that problem just disappeared.

Thank you!

Christian
Reply all
Reply to author
Forward
0 new messages