code: def test_get_filename_for_language(app):
      app.env.temp_data["docname"] = "index"
  
      # language is en
      app.env.config.language = "en"
      assert (
          i18n.get_image_filename_for_language("foo.png", app.env)
          == "foo.en.png"
      )
      assert (
          i18n.get_image_filename_for_language("foo.bar.png", app.env)
          == "foo.bar.en.png"
      )
      assert (
          i18n.get_image_filename_for_language("dir/foo.png", app.env)
          == "dir/foo.en.png"
      )
      assert (
          i18n.get_image_filename_for_language("../foo.png", app.env)
          == "../foo.en.png"
      )
      assert (
          i18n.get_image_filename_for_language("foo", app.env)
          == "foo.en"
      )
  
      # modify figure_language_filename and language is 'en'
      app.env.config.language = "en"
      app.env.config.figure_language_filename = (
          "images/{language}/{root}{ext}"
      )
      assert (
          i18n.get_image_filename_for_language("foo.png", app.env)
          == "images/en/foo.png"
      )
      assert (
          i18n.get_image_filename_for_language("foo.bar.png", app.env)
          == "images/en/foo.bar.png"
      )
      assert (
          i18n.get_image_filename_for_language(
              "subdir/foo.png", app.env
          )
          == "images/en/subdir/foo.png"
      )
      assert (
          i18n.get_image_filename_for_language("../foo.png", app.env)
          == "images/en/../foo.png"
      )
      assert (
          i18n.get_image_filename_for_language("foo", app.env)
          == "images/en/foo"
      )
  
      # new path and basename tokens
      app.env.config.language = "en"
      app.env.config.figure_language_filename = (
          "{path}{language}/{basename}{ext}"
      )
      assert (
          i18n.get_image_filename_for_language("foo.png", app.env)
          == "en/foo.png"
      )
      assert (
          i18n.get_image_filename_for_language("foo.bar.png", app.env)
          == "en/foo.bar.png"
      )
      assert (
          i18n.get_image_filename_for_language(
              "subdir/foo.png", app.env
          )
          == "subdir/en/foo.png"
      )
      assert (
          i18n.get_image_filename_for_language("../foo.png", app.env)
          == "../en/foo.png"
      )
      assert (
          i18n.get_image_filename_for_language("foo", app.env)
          == "en/foo"
      )
  
      # invalid figure_language_filename
      app.env.config.figure_language_filename = "{root}.{invalid}{ext}"
      with pytest.raises(SphinxError):
          i18n.get_image_filename_for_language("foo.png", app.env)
  
      # docpath (for a document in the top of source directory)
      app.env.config.language = "en"
      app.env.config.figure_language_filename = (
          "/{docpath}{language}/{basename}{ext}"
      )
      assert (
          i18n.get_image_filename_for_language("foo.png", app.env)
          == "/en/foo.png"
      )
  
      # docpath (for a document in the sub directory)
      app.env.temp_data["docname"] = "subdir/index"
      assert (
          i18n.get_image_filename_for_language("foo.png", app.env)
          == "/subdir/en/foo.png"
      )
  
file_path: sphinx/tests/test_util/test_util_i18n.py
imports: import datetime
  import os
  import babel
  import pytest
  from babel.messages.mofile import read_mo
  from sphinx.errors import SphinxError
  from sphinx.util import i18n
label_desc: Use image node_id 6 for calling a global function with example usage: test_get_filename_for_language(app) without return types