abakan-zz / ablog

ABlog for blogging with Sphinx
ablog.readthedocs.org
Other
122 stars 34 forks source link

Post langulage #15

Closed abakan-zz closed 10 years ago

abakan-zz commented 10 years ago

Add :language: option to post directive, that works similar to :author: and :location: options, that is:

This may be satisfactory, but having a standard mapping from language codes to language names and then letting the user to overwrite these display names could be useful. What would be the best way to get this?

@marble what do you think?

abakan-zz commented 10 years ago

@marble, if you are using ablog from github, you can try :language: option. There is also languages.html sidebar. If you don't find a chance, I plan to release a newer version over the weekend.

I looked into sphinx, but couldn't find a dictionary mapping lang code to display name, and I didn't want to require another package that does this. Let me know if you have any ideas.

marble commented 10 years ago

Hi Ahmet, I'm very happy with this improvement. Actually I had tested it already from the devel branch but missed to give you positive feedback. I did a lot of "diving into Sphinx code" instead to understand how l10n and i18n is handled. And the answer is: gettext is the technique: https://docs.python.org/2/library/gettext.html And in the constructor of a Sphinx app in sphinx/application.py/Sphinx.init an app.translation attribute is created IF language = 'xx' is in the Sphinx settings. jinja2glue.py will pick that up (from builder.app.translation) and make it available in the Jinja2 environment as well.

But the translation instance will only contain translations for the one and only language that had been given in the Sphinx settings. So there is no mapping for other languages available right away.

It can be done of course. The answer is here: https://docs.python.org/2/library/gettext.html#changing-languages-on-the-fly But I don't have a picture of how to integrate that solution in a clean and easy way (yet!).

abakan-zz commented 10 years ago

Great! I some looked into Sphinx code too, and couldn't find a mapping of codes to full names. I thought I could read contents of locale folder and build a mapping but that would be an overkill, and maybe not ideal since display names would be in English and one may prefer display name in that language rather than English. Adding a manually created mapping of codes to display names in that language could be a simple and more ideal solution. What do you think?

marble commented 10 years ago

Cool! I just got a local developmental version of ablog going which takes notice of the :language: option of a post directive and then renders THAT post accordingly in the specified language. It's done in a clean and Sphinx-like way and doesn't interfere otherwise. I'll create a clean version of the code soon and send you a pull request.

Hah, now I have everything at hand what is needed to start with my blog!!!