pongo2 icon indicating copy to clipboard operation
pongo2 copied to clipboard

Support internationalization / multi language templates

Open flosch opened this issue 11 years ago • 13 comments

(stub) i18n/i10n

  • Tags
  • Filters

Open questions:

  • How to design/implement?
  • Any existing solutions in Go for i18n/i10n?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

flosch avatar Oct 03 '14 00:10 flosch

+1

Davmuz avatar Dec 15 '14 23:12 Davmuz

+1 Honestly we have some crunches to solve this task, but I hope you have more beautiful solution.

digitalcrab avatar Dec 16 '14 08:12 digitalcrab

Haven't thought any deeper about this issue yet; I appreciate any design suggestions or ideas for supporting a good internationalization in templates. Ideas welcome!

flosch avatar Dec 16 '14 09:12 flosch

The most important functions are the tags "trans" and "blocktrans". It is very useful that Pongo2 could parse the templates and return the trans and blocktrans strings with the file name, row and column. This data can be used by another system in order to help the creation of the translation maps.

Davmuz avatar Dec 16 '14 23:12 Davmuz

Are there any gettext or other sort of translation libraries out there in the Go world you guys know of? I prefer using the PO file format since there are already some nice tools out there for creating/managing translations (for example Poedit). Doing so would require me to write a translation library first (for PO files/gettext) and to use this library in pongo2 afterwards.

flosch avatar Dec 17 '14 11:12 flosch

Would really suck to hard dependency on something like gettext, as I won't be using this for example and want to limit the number of dependencies I'm using. I like how light pongo2 is on dependencies, please bear this in mind :).

ahall avatar Dec 17 '14 12:12 ahall

Absolutely. pongo2 only uses the stdlib; any tags/filters which require external dependencies are in pongo2-addons. If it turns out we need/use some sort of external 3rd-party-library (which is not developed by me) it won't go into pongo2, but in pongo2-i18n or something like that which then will be easy importable like pongo2-addons.

flosch avatar Dec 17 '14 12:12 flosch

Any progress / best practice / example solutions for this issue?

mr-july avatar Apr 02 '17 13:04 mr-july

Dear all, any progress of the i18n support?

  • Any suggestion to implement something like {{ _("orig string") }} in template file like Jinja2?
  • How can i register a Golang function and use it in pongo2 template file like {{ fn("orig string") }} for translation? Is it possible and a good idea?

iredmail avatar Mar 05 '21 09:03 iredmail

No progress yet. I'm happy to discuss proposals and accept pull requests. You can pass the function through the context and call it from there.

flosch avatar Mar 06 '21 10:03 flosch

Dear @flosch,

Thanks for the reply.

Maybe not the best solution, but want to share my idea:

  • improve pongo2 to allow syntax {{ _(“text”) }}. So that we can use tool like pybabel to extract strings from (pongo2) html files for translation in pot file format, then compile the pot file to “.mo” file. It should be better if pongo2 offers command line tool to extract/update pot file directly, this way we don't need to rely on Python + Babel.
  • use tool like gotext to read mo files in Golang.

Any idea / comment?

iredmail avatar Mar 06 '21 11:03 iredmail

Dear @flosch,

Any comment?

iredmail avatar Mar 09 '21 01:03 iredmail

I just published an implementation of the 'trans'/'blocktrans'-tags that I've been using for a while in a private project.

It contains an implementation that uses 'gotext' under the hood, but can be used with other translators if needed.

The repo is here: https://github.com/yzzyx/pongo-trans The project in the _example-folder showcases how to use it with pongo2 in a webserver setting.

As a bonus, I've published a related repo to extract the strings used in tags in templates and updating the po-files that works in a very similar fashion to djangos 'makemessage'. It can be found here

yzzyx avatar Jan 04 '23 20:01 yzzyx