Hey Martin, i guess it would be pretty easy to create a solution using Jinja2 templates and the JSON format you already have. I don't know if you want the user to be able to switch languages, or if it's a configuration option. In both cases you just need a little bit of logic that loads the specific JSON file to memory and then serves it to the template using a context processor with a dict (see here: http://flask.pocoo.org/docs/1.0/templating/). After that you can simply use that dict inside of your templates to display the messages in the configured language.
Kind regards, -- Hay On Tue, Sep 18, 2018 at 10:48 PM Martin Urbanec <[email protected]> wrote: > > Hi Guilherme, > > well, maybe I should have explained what I'm trying to do in the original > email. Fixing this mistake now. > > I have a tool called Wikinity. The tool takes data from Wikidata and displays > items with no image uploaded. It became to be used by Czech Commons users in > the preparation step for their photo trip. The source is awful, to say the > most important parts from how its written: > > Frontend is in public/*.php. Those files used to be HTML files while the tool > was in one language only. I switched them to PHP only to be able to use > Intuition. > Backend logic is in public/*.py. for the main purpose of tool, public/map.py > is important, which selects appropriate Wikidata query (stored in > queries/*.txt) based on GET parameters and creates a map. > JavaScript just displays the map generated by map.py. > Other files are used for other things like storing queries. > > Yeah, I know its awful (but working :D). I plan to rewrite it. As I already > use Translatewiki, which generates locales in certain format, I want to keep > it. The fornat is straightforward to me and not like gettext which I managed > to understood, but I think this is more clear. Of course, you might not > agree, that's my current point of view. > > My plan is to convert this into a simple Flask app, which should incorporate > several backend CGI scripts written in Python into one file with much more > clear structure. This Flask app should ofc do the same things like the > current tool does. I know how to do everything from the function side. The > only one thing I'm thinking about is the localization - more certainly, what > way I should use to use locales in this format in a Flask app (more > precisely, in its Jinja2 templates, I do not have anything to localize in the > Python part). > > BTW, I tried to use Flask-Babel and I manged to have working localization. > The only one thing I don't like is that it uses gettext, which I don't like > and its not like "modify this json file and the locales will change > automatically", but "modify this .po file, then compile it it and maybe it > will work". > > Martin > > út 18. 9. 2018 v 19:10 odesílatel Guilherme Gonçalves > <[email protected]> napsal: >> >> Hi Martin, >> >> I know of a few approaches, depending on the complexity of your tool: >> >> You can get pretty far with having your strings in, say, JSON files that you >> load and format yourself in code based on placeholders. >> The Python standard library has a built-in gettext module if you prefer a >> more standard format. >> For a more comprehensive solution that adds date formatting, I heard good >> things about Flask-Babel, but never used it myself. >> >> Whichever way you choose, I'd definitely recommend managing the translations >> through TranslateWiki, which you might already know about. >> >> Em ter, 18 de set de 2018 às 15:14, Martin Urbanec >> <[email protected]> escreveu: >>> >>> Hi, >>> >>> I'm sometimes use Flask for my Toolforge tools. I'd like to localize them, >>> ideally with messages directory in similar format like MediaWiki has in >>> i18n directory. >>> >>> I know about Intuition for PHP, does anybody know about similar thing for >>> Flask application? >>> >>> Best, >>> Martin >>> _______________________________________________ >>> Wikimedia Cloud Services mailing list >>> [email protected] (formerly [email protected]) >>> https://lists.wikimedia.org/mailman/listinfo/cloud >> >> >> >> -- >> Guilherme P. Gonçalves >> _______________________________________________ >> Wikimedia Cloud Services mailing list >> [email protected] (formerly [email protected]) >> https://lists.wikimedia.org/mailman/listinfo/cloud > > _______________________________________________ > Wikimedia Cloud Services mailing list > [email protected] (formerly [email protected]) > https://lists.wikimedia.org/mailman/listinfo/cloud _______________________________________________ Wikimedia Cloud Services mailing list [email protected] (formerly [email protected]) https://lists.wikimedia.org/mailman/listinfo/cloud
