title: How to switch between two languages in Flask?
body: <p>I want to make my site in two different languages, am using <code>Flask-Babel</code> for this purpose .</p>
  
  <p>Here is my <strong>settings.py</strong> configurations:</p>
  
  <pre><code>LANGUAGES = {
      'en': 'English',
      'ru': 'Russian'
  }
  </code></pre>
  
  <p>Here you can see a dictionary including the two languages that am using in my app.</p>
  
  <p>here is the <strong>views.py</strong>:</p>
  
  <pre><code>from settings import LANGUAGES
  
  @app.before_request
  @babel.localeselector
  def before_request():
      if request.view_args and 'lang' in request.view_args:
          g.current_lang = request.view_args['lang']
          request.view_args.pop('lang')
  
  @app.context_processor
  def inject_url_for():
      return {
          'url_for': lambda endpoint, **kwargs: flask_url_for(
          endpoint, lang=g.current_lang, **kwargs
          )
      }
  url_for = inject_url_for()['url_for']
  </code></pre>
  
  <p>The inject_url_for function means that all the url_for() calls in the application need to be modified
  to have an extra parameter called lang to be passed, and that's what i did exactly , here is the <strong>index</strong> function:</p>
  
  <pre><code>@app.route('/&lt;lang&gt;/')
  def index(page=1):
  
      user = User.query.filter_by(username='Reznov').first_or_404()
      blogs = Blog.query.count()
      blog_data = Blog.query.first()
      blog = Blog.query.first()
      posts = Post.query.filter_by(live=True).order_by(Post.publish_date.desc()).paginate(page, app.config['POSTS_PER_PAGE'], False)
      scshot = ScreenShot.query.filter_by(live=True).order_by(ScreenShot.publish_date.desc()).limit(4)
      post = Post.query.first()
  
      context = {
          'user': user,
          'blogs': blogs,
          'blog_data':blog_data,
          'blog':blog,
          'posts':posts,
          'scshot':scshot,
          'post':post
      }
  
      return render_template('blog/index.html', **context)
  </code></pre>
  
  <p>Sounds good right ?</p>
  
  <p>Now if i ran the application as it is, nothing changes, it just gives me the default language which is English, but won't work if i switch it to Russian .</p>
  
  <p>Please any help would be very appreciated :) .</p>