Oddaja Tranzistor - uvod

Ko so nam Resnično Resničnost ukinili, sem mislil, da še dolgo ne bom imel prilike, da bi se pokazal pred kamero, še posebej na nacionalki. No, na srečo sta se na začetku leta name spomnila Miha Šalehar in Siniša Gačič in mi ponudila 3 minute / teden, da našemu ljudstvu predstavim to, kar sem zanimivega izvedel v zadnjem tednu. Oddaja se imenuje Tranzistor, namenjena je študentom, dijakom in brezposelnim. Snemanja so ob torkih, oddaja gre ven v soboto, tako da novice niso ažurne, ampak vsaj SO.

V prihodnji oddaji (ki bo na sporedu v soboto, 31. 1. 2009), bom gledalce poizkusil usmeriti na svoj blog. S kančkom sreče me bo plaz komentarjev motiviral, da bi tule objavil še kaj zanimivega. Mimogrede, če imate na računalniku nastavljen slovenski jezik in vse skupaj izgleda nekam čudno, se opravičujem, prevajanje samega bloga je še v teku.

Читать далее…

Turbogears i18n pains

The final problem I have run into with TurboGears is the poor documentation regarding i18n with Genshi templates. The only way I have been able to get gettext to work for this blog was by using sourcecode from Transifex. To get i18n to work with genshi templates, I added this to config/app.cfg:

session_filter.on = True
i18n.run_template_filter = True

i18n.domain = "cblog"
i18n.locale_dir = "locales/"
i18n.po_view_dir = "locales/view/"

i18n.locale_dir = "locales/"

and this to controllers.py:

# i18n support
from turbogears.i18n import gettext
from genshi.filters import Translator
import turbogears.view

def genshi_loader_callback(template):
    template.filters.insert(0, Translator(gettext))

def init_callback():
    turbogears.view.engines['genshi'].loader.callback = genshi_loader_callback

turbogears.startup.call_on_startup.append( init_callback )

config.update({'genshi.loader_callback': genshi_loader_callback})

# i18n support - end

To create the translation files, I followed the instructions from the Genshi i18n page. First, I created a mappings.cfg file containing:

# Extraction from Python source files
[python: **.py]
# Extraction from Genshi HTML and text templates
[genshi: **/templates/**.html]

And then ran:

pybabel extract -o locales/cblog.pot -F ./mappings.cfg cblog
pybabel init -D cblog -i locales/cblog.pot -d locales/ -l en # for the english language
pybabel compile -D cblog -d locales/ -f --statistics

Unfortunately, in order for the changes to the translated strings to take effect, the application needs to be restarted. The need to restart the server each time a translated string changes seems silly. Also, I spent more than 3 days hunting for documentation on how to actually get the i18n to work. Hopefully, doing the same with Django will be less painful.

Читать далее…

Better templates using gettext

which is supposed to produce "category" if there is exactly one category and "categories" if there are multiple categories.

There is a better way to handle this, which is to use the ngettext function. Like this::
${ngettext("%d category", "%d categories", numtags) % numtags}

By using ngettext it becomes possible to translate the blog into languages where counting is done differently than in English. Which is what I intend to do next.

Читать далее…

KID to Genshi migration

To change a KID template into a Genshi format, all you have to do is: 1. in all templates except SiteTemplate replace:

import SiteTemplate
<html py:layout="SiteTemplate"


<html xmlns:py="http://genshi.edgewall.org/"

2. Add:

<xi:include href="SiteTemplate.html" />

to every template file except SiteTemplate.html .

3. In SiteTemplate, change:

<html xmlns="http://www.w3.org/1999/xhtml"


<html xmlns:py="http://genshi.edgewall.org/" py:strip="">

4. wrap all turbogears widget calls in ET(), for example:

    form_attrs=dict(id='articleform'), tags=tags))}

And that's it. Hopefully, this concludes the mind-numbing template translations for now. Next step: using ngettext() for things like "There are N Comments for this article".

Читать далее…

TurboGears && Debian == problems

First of all, the TurboGears package from Debian is old and outdated. In fact, as of Jan. 6. 2009, it doesn't even work. The "preferred" solution to this problem is to install all your dependencies in a virtualenv directory. On top of that, most of the TurboGears-based blogs don't even seem to work out of the box (I'm not sure if this was due to a PEBKAC or not). In the end, I decided to install CBlog . Unfortunately, CBlog uses cheetah templates which don't work on Debian's version of TurboGears. I have therefore rewritten all the templates in KID, only to be told by TurboGears developers that I should be using Genshi . I've also noticed that if I use py:layout in a KID template, the template doesn't get reloaded automatically. Paradoxically, this isn't really that problematic since the AutoReload feature of TurboGears affects it's performance so a production server is supposed to be restarted every time your web app is updated.

Anyway, the blog is up and I intend to start filling it with useful tips and information regarding computing in general in the following weeks.

Oh, and feel free to post some spam in the comments, filtering is still on my TODO list.

Читать далее…

Blog vzpostavljen!

Berete prvi post na blogu, na katerem boste v bližnji prihodnosti lahko prebrali kaj več poučnih napotkov v zvezi z računalništvom in digitalnimi tehnologijami. Če želite, lahko med komentarji začnete puščati spam.

Hvala za pozornost.

Читать далее…

Welcome to CBlog!


What to do next:

  1. Log in with username and password admin and click on Administration (at the bottom of the sidebar to the left).
  2. Create a new user and add him to the Blog publishers group.
  3. Close the administration window, log out and then log in again as the new user.
  4. Click on Post new article and start adding articles to your blog.

Share and enjoy!

Читать далее…