diff --git a/mkdocs_rss_plugin/util.py b/mkdocs_rss_plugin/util.py index 20c88794..35264c38 100644 --- a/mkdocs_rss_plugin/util.py +++ b/mkdocs_rss_plugin/util.py @@ -560,7 +560,8 @@ def guess_locale(mkdocs_config: Config) -> str or None: # Some themes implement a locale or a language setting if "theme" in mkdocs_config and "locale" in mkdocs_config.get("theme"): - return mkdocs_config.get("theme")._vars.get("locale") + locale = mkdocs_config.get("theme")._vars.get("locale") + return f"{locale.language}-{locale.territory}" elif "theme" in mkdocs_config and "language" in mkdocs_config.get("theme"): return mkdocs_config.get("theme")._vars.get("language") else: diff --git a/tests/fixtures/mkdocs_lang_with_territory.yml b/tests/fixtures/mkdocs_lang_with_territory.yml new file mode 100644 index 00000000..f765fc60 --- /dev/null +++ b/tests/fixtures/mkdocs_lang_with_territory.yml @@ -0,0 +1,12 @@ +site_name: Test RSS Plugin +site_description: Test a language code with territory +site_url: https://guts.github.io/mkdocs-rss-plugin + +use_directory_urls: true + +plugins: + - rss + +theme: + name: mkdocs + locale: en_US diff --git a/tests/test_build.py b/tests/test_build.py index 16c35289..7f8ca386 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -330,6 +330,32 @@ def test_simple_build_item_length_unlimited(self): len(feed_item.description), 150, feed_item.title ) + def test_simple_build_lang_with_territory(self): + with tempfile.TemporaryDirectory() as tmpdirname: + cli_result = self.build_docs_setup( + testproject_path="docs", + mkdocs_yml_filepath=Path( + "tests/fixtures/mkdocs_lang_with_territory.yml" + ), + output_path=tmpdirname, + strict=True, + ) + + if cli_result.exception is not None: + e = cli_result.exception + logger.debug(format_exception(type(e), e, e.__traceback__)) + + self.assertEqual(cli_result.exit_code, 0) + self.assertIsNone(cli_result.exception) + + # created items + feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_created.xml") + self.assertEqual(feed_parsed.feed.get("language"), "en-US") + + # updated items + feed_parsed = feedparser.parse(Path(tmpdirname) / "feed_rss_updated.xml") + self.assertEqual(feed_parsed.feed.get("language"), "en-US") + def test_simple_build_pretty_print_enabled(self): with tempfile.TemporaryDirectory() as tmpdirname: cli_result = self.build_docs_setup(