# Path: mkdocs/localization.py
# def install_translations(env, locale, theme_dirs):
#     if has_babel:
#         env.add_extension('jinja2.ext.i18n')
#         translations = _get_merged_translations(theme_dirs, 'locales', locale)
#         if translations is not None:
#             env.install_gettext_translations(translations)
#         else:
#             env.install_null_translations()
#             if locale.language != 'en':
#                 log.warning(
#                     f"No translations could be found for the locale '{locale}'. "
#                     'Defaulting to English.'
#                 )
#     else:  # pragma: no cover
#         # no babel installed, add dummy support for trans/endtrans blocks
#         env.add_extension(NoBabelExtension)
#         env.install_null_translations()
# 
# def parse_locale(locale):
#     try:
#         return Locale.parse(locale, sep='_')
#     except (ValueError, UnknownLocaleError, TypeError) as e:
#         raise ValidationError(f'Invalid value for locale: {str(e)}')
# 
# Path: mkdocs/tests/base.py
# def tempdir(files=None, **kw):
#     """
#     A decorator for building a temporary directory with prepopulated files.
# 
#     The temporary directory and files are created just before the wrapped function is called and are destroyed
#     immediately after the wrapped function returns.
# 
#     The `files` keyword should be a dict of file paths as keys and strings of file content as values.
#     If `files` is a list, then each item is assumed to be a path of an empty file. All other
#     keywords are passed to `tempfile.TemporaryDirectory` to create the parent directory.
# 
#     In the following example, two files are created in the temporary directory and then are destroyed when
#     the function exits:
# 
#         @tempdir(files={
#             'foo.txt': 'foo content',
#             'bar.txt': 'bar content'
#         })
#         def example(self, tdir):
#             assert os.path.isfile(os.path.join(tdir, 'foo.txt'))
#             pth = os.path.join(tdir, 'bar.txt')
#             assert os.path.isfile(pth)
#             with open(pth, 'r', encoding='utf-8') as f:
#                 assert f.read() == 'bar content'
#     """
#     files = {f: '' for f in files} if isinstance(files, (list, tuple)) else files or {}
# 
#     kw['prefix'] = 'mkdocs_test-' + kw.get('prefix', '')
# 
#     def decorator(fn):
#         @wraps(fn)
#         def wrapper(self, *args):
#             with TemporaryDirectory(**kw) as td:
#                 for path, content in files.items():
#                     pth = os.path.join(td, path)
#                     utils.write_file(content.encode(encoding='utf-8'), pth)
#                 return fn(self, td, *args)
#         return wrapper
#     return decorator
# 
# Path: mkdocs/config/base.py
# class ValidationError(Exception):
#     """Raised during the validation process of the config on errors."""


import unittest
from mkdocs.localization import install_translations, parse_locale
from mkdocs.tests.base import tempdir
from mkdocs.config.base import ValidationError
        locale = parse_locale('en')
        self.assertEqual(locale.language, 'en')

    def test_valid_language_territory(self):
        locale = parse_locale('en_US')
        self.assertEqual(locale.language, 'en')
        self.assertEqual(locale.territory, 'US')
        self.assertEqual(str(locale), 'en_US')

    def test_unknown_locale(self):
        self.assertRaises(ValidationError, parse_locale, 'foo')

    def test_invalid_locale(self):
        self.assertRaises(ValidationError, parse_locale, '42')

    @tempdir()
    def test_no_translations_found(self, dir_without_translations):
        install_translations(self.env, parse_locale('fr_CA'), [dir_without_translations])
        self.env.install_null_translations.assert_called_once()

    @tempdir
    def test_translations_found(self, tdir):
        translations = unittest.mock.Mock()

        with unittest.mock.patch('mkdocs.localization.Translations.load', return_value=translations):
            install_translations(self.env, parse_locale('en'), [tdir])

        self.env.install_gettext_translations.assert_called_once_with(translations)

    @tempdir()

# Path: mkdocs/localization.py
# def install_translations(env, locale, theme_dirs):
#     if has_babel:
#         env.add_extension('jinja2.ext.i18n')
#         translations = _get_merged_translations(theme_dirs, 'locales', locale)
#         if translations is not None:
#             env.install_gettext_translations(translations)
#         else:
#             env.install_null_translations()
#             if locale.language != 'en':
#                 log.warning(
#                     f"No translations could be found for the locale '{locale}'. "
#                     'Defaulting to English.'
#                 )
#     else:  # pragma: no cover
#         # no babel installed, add dummy support for trans/endtrans blocks
#         env.add_extension(NoBabelExtension)
#         env.install_null_translations()
# 
# def parse_locale(locale):
#     try:
#         return Locale.parse(locale, sep='_')
#     except (ValueError, UnknownLocaleError, TypeError) as e:
#         raise ValidationError(f'Invalid value for locale: {str(e)}')
# 
# Path: mkdocs/tests/base.py
# def tempdir(files=None, **kw):
#     """
#     A decorator for building a temporary directory with prepopulated files.
# 
#     The temporary directory and files are created just before the wrapped function is called and are destroyed
#     immediately after the wrapped function returns.
# 
#     The `files` keyword should be a dict of file paths as keys and strings of file content as values.
#     If `files` is a list, then each item is assumed to be a path of an empty file. All other
#     keywords are passed to `tempfile.TemporaryDirectory` to create the parent directory.
# 
#     In the following example, two files are created in the temporary directory and then are destroyed when
#     the function exits:
# 
#         @tempdir(files={
#             'foo.txt': 'foo content',
#             'bar.txt': 'bar content'
#         })
#         def example(self, tdir):
#             assert os.path.isfile(os.path.join(tdir, 'foo.txt'))
#             pth = os.path.join(tdir, 'bar.txt')
#             assert os.path.isfile(pth)
#             with open(pth, 'r', encoding='utf-8') as f:
#                 assert f.read() == 'bar content'
#     """
#     files = {f: '' for f in files} if isinstance(files, (list, tuple)) else files or {}
# 
#     kw['prefix'] = 'mkdocs_test-' + kw.get('prefix', '')
# 
#     def decorator(fn):
#         @wraps(fn)
#         def wrapper(self, *args):
#             with TemporaryDirectory(**kw) as td:
#                 for path, content in files.items():
#                     pth = os.path.join(td, path)
#                     utils.write_file(content.encode(encoding='utf-8'), pth)
#                 return fn(self, td, *args)
#         return wrapper
#     return decorator
# 
# Path: mkdocs/config/base.py
# class ValidationError(Exception):
#     """Raised during the validation process of the config on errors."""


# Path: mkdocs/tests/localization_tests.py
import unittest
from mkdocs.localization import install_translations, parse_locale
from mkdocs.tests.base import tempdir
from mkdocs.config.base import ValidationError

        locale = parse_locale('en')
        self.assertEqual(locale.language, 'en')

    def test_valid_language_territory(self):
        locale = parse_locale('en_US')
        self.assertEqual(locale.language, 'en')
        self.assertEqual(locale.territory, 'US')
        self.assertEqual(str(locale), 'en_US')

    def test_unknown_locale(self):
        self.assertRaises(ValidationError, parse_locale, 'foo')

    def test_invalid_locale(self):
        self.assertRaises(ValidationError, parse_locale, '42')

    @tempdir()
    def test_no_translations_found(self, dir_without_translations):
        install_translations(self.env, parse_locale('fr_CA'), [dir_without_translations])
        self.env.install_null_translations.assert_called_once()

    @tempdir
    def test_translations_found(self, tdir):
        translations = unittest.mock.Mock()

        with unittest.mock.patch('mkdocs.localization.Translations.load', return_value=translations):
            install_translations(self.env, parse_locale('en'), [tdir])

        self.env.install_gettext_translations.assert_called_once_with(translations)

    @tempdir()

    @tempdir()