flosch / pongo2

Django-syntax like template-engine for Go
https://www.schlachter.tech/pongo2
MIT License
2.85k stars 269 forks source link

Support internationalization / multi language templates #52

Open flosch opened 9 years ago

flosch commented 9 years ago

(stub) i18n/i10n

Open questions:

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

Davmuz commented 9 years ago

+1

digitalcrab commented 9 years ago

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

flosch commented 9 years ago

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!

Davmuz commented 9 years ago

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.

flosch commented 9 years ago

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.

ahall commented 9 years ago

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 :).

flosch commented 9 years ago

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.

mr-july commented 7 years ago

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

iredmail commented 3 years ago

Dear all, any progress of the i18n support?

flosch commented 3 years ago

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.

iredmail commented 3 years ago

Dear @flosch,

Thanks for the reply.

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

Any idea / comment?

iredmail commented 3 years ago

Dear @flosch,

Any comment?

yzzyx commented 1 year ago

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