1

The setup of the problem is simple enough:

  • an user selects a language preference (this preference can be read from the user’s session);
  • based on this choice, load the appropriate .mo from the available translations;
  • (no separate domains are set up, if it makes any difference)

Problem: since this return has to be done outside the scope of the flask app, it cannot be instantiated and to use @babel.localeselector. Instead, I use a simple function based on webapp2 i18n’ extension which, using Babel’s support function, loads a given translation and returns a translation instance (Translations: "PROJECT VERSION"). (inb4 ‘why not use webapp2 already?’ too many libs already).

From this point on, it is not clear to me what to do with this instance. How can I get Babel to use this specific instance? (at the moment, it always uses the default one, no 'best_match' involved).

davidism
  • 121,510
  • 29
  • 395
  • 339
isra
  • 21
  • 3

1 Answers1

0

Solved by just using the flask app and the way I wanted to avoid - on every request, there is a callback to the app instance and to the localeselector decorator, language is set previously in an attribute in flask.g. Basically, by the books I guess.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
isra
  • 21
  • 3