pyformat.info icon indicating copy to clipboard operation
pyformat.info copied to clipboard

Make it translatable

Open humitos opened this issue 10 years ago • 3 comments

Hi, I found this really interesting and I looked at the code to see how I can translate it but I found that it's done using docstring and I don't know if there is a way to make them translatable.

Do you know if it is possible to do it in the way that it's written?

Thanks,

humitos avatar Aug 13 '15 23:08 humitos

Hi :)

No, the current structure doesn't really lend itself to easily support translations. Of course, we could simple wrap the whole docstring around some gettext-function but that would end up being quite a mess.

A cleaner approach would perhaps be taking the module-path of each function and use that as key to look up the description text somewhere else.

That issue set aside, there is also the question of how to serve the translations. My first idea here would be to generate something like en.html, fr.html, de.html files and add a dropdown to all of them where the user can switch the language.

The big problem is still where to store the translations. @ulope do you have any ideas?

zerok avatar Aug 16 '15 06:08 zerok

I think serving the translated versions shouldn't be a big problem. From a quick google it seems to be relatively easy to get nginx to serve different static files based on the Accept-Language header. Adding a dropdown that sets an override cookie for the cases where the default fails should also not be that difficult.

As @zerok said it's much less clear where and how the translations should be stored. Since the traditional translation tools (gettext, etc.) are usually geared towards translating (relatively) short UI elements instead of actual page content they aren't very well suited for our site.

We could use some custom system that loads the translations from files (JSON, YAML or even Python come to mind) during generation of the output. That seems a bit cumbersome to me however.

Maybe the best solution would be to drop this "tests-are-content" scheme entirely and just store the whole content in some kind of structured file. We still could have tests for that via pytest's pytest_generate_tests hook.

ulope avatar Aug 18 '15 13:08 ulope

With the switch to Lektor we should have a much easier time with translated content.

ulope avatar Oct 12 '16 00:10 ulope