Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support internationalization / multi language templates #52

Open
flosch opened this issue Oct 3, 2014 · 13 comments
Open

Support internationalization / multi language templates #52

flosch opened this issue Oct 3, 2014 · 13 comments

Comments

@flosch
Copy link
Owner

flosch commented Oct 3, 2014

(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.

@Davmuz
Copy link

Davmuz commented Dec 15, 2014

+1

@digitalcrab
Copy link
Contributor

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

@flosch
Copy link
Owner Author

flosch commented Dec 16, 2014

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
Copy link

Davmuz commented Dec 16, 2014

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
Copy link
Owner Author

flosch commented Dec 17, 2014

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
Copy link
Contributor

ahall commented Dec 17, 2014

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
Copy link
Owner Author

flosch commented Dec 17, 2014

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
Copy link

mr-july commented Apr 2, 2017

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

@iredmail
Copy link
Contributor

iredmail commented Mar 5, 2021

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?

@flosch
Copy link
Owner Author

flosch commented Mar 6, 2021

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
Copy link
Contributor

iredmail commented Mar 6, 2021

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
Copy link
Contributor

iredmail commented Mar 9, 2021

Dear @flosch,

Any comment?

@yzzyx
Copy link

yzzyx commented Jan 4, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants