August 11, 2021

How to Surround Highlighted Text With a Custom Snippet

In order to mark strings as “translatable” in Flask via Flask-WTF, you need to apply a special syntax. This means, e.g. in a Jinja template a string like Conference has to be transformed into {{ _('Conference') }}. This is a very tedious work, so I created a shortcut for it. Add the following lines to your keybindings.json: "key": "ctrl+shift+alt+0", "command": "editor.action.insertSnippet", "when": "editorHasSelection || editorHasMultipleSelections", "args": { "snippet": "{{ _('${TM_SELECTED_TEXT}') }}" } I used “ctrl+shift+alt+0” as on keyboard with a German layout the closing curly brace is on the same key as the 0....

August 13, 2020

How Can You Inject the Language as String Into a Jinja Template

I created a multilingual project using Flask with the help of Flask-Babel. While the translation mechanism via GNU gettext itself is pretty straightforward, I did not know how to inject the actual language into the Jinja template, so I can use it to set <html lang="xxx">. While it is odd that this is not mentioned in the documentation, once again StackOverflow offered solutions. solution one Just translate the language! <html lang="{{ _('en') }}"> That was too simple to think of :-)...