From 66287b2d1468b51a3a1b12134a10c6d7aa8f09c0 Mon Sep 17 00:00:00 2001 From: Tim Vink Date: Fri, 31 Oct 2025 16:05:42 +0100 Subject: [PATCH 1/6] Fix locale with hyphens --- .../plugin.py | 6 ++++++ .../mkdocs_theme_locale_and_language_5char.yml | 11 +++++++++++ tests/test_builds.py | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/basic_project/mkdocs_theme_locale_and_language_5char.yml diff --git a/src/mkdocs_git_revision_date_localized_plugin/plugin.py b/src/mkdocs_git_revision_date_localized_plugin/plugin.py index 985a0a6..1f3497a 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/plugin.py +++ b/src/mkdocs_git_revision_date_localized_plugin/plugin.py @@ -291,6 +291,12 @@ def on_page_markdown(self, markdown: str, page: Page, config: config_options.Con if not locale: locale = self.config.get("locale") + # Normalize locale for Babel: convert hyphens to underscores (e.g., pt-BR -> pt_BR) + # This is needed for compatibility with mkdocs-static-i18n and other plugins + # that may use hyphenated locale codes, while Babel expects underscores + if locale: + locale = str(locale).replace("-", "_") + # Retrieve git commit timestamp # Except for generated pages (f.e. by mkdocs-gen-files plugin) if getattr(page.file, "generated_by", None): diff --git a/tests/fixtures/basic_project/mkdocs_theme_locale_and_language_5char.yml b/tests/fixtures/basic_project/mkdocs_theme_locale_and_language_5char.yml new file mode 100644 index 0000000..9fd0d8f --- /dev/null +++ b/tests/fixtures/basic_project/mkdocs_theme_locale_and_language_5char.yml @@ -0,0 +1,11 @@ +site_name: test gitrevisiondatelocalized_plugin +use_directory_urls: true + +theme: + name: 'material' + language: zh + +plugins: + - search + - git-revision-date-localized: + locale: "pt-BR" diff --git a/tests/test_builds.py b/tests/test_builds.py index 310727c..fac88d5 100644 --- a/tests/test_builds.py +++ b/tests/test_builds.py @@ -341,6 +341,7 @@ def validate_mkdocs_file(temp_path: str, mkdocs_yml_file: str): "basic_project/mkdocs.yml", "basic_project/mkdocs_theme_timeago_locale.yml", "basic_project/mkdocs_theme_language.yml", + "basic_project/mkdocs_theme_locale_and_language_5char.yml", "basic_project/mkdocs_theme_locale_and_language.yml", "basic_project/mkdocs_theme_locale_disabled.yml", "basic_project/mkdocs_theme_timeago.yml", @@ -376,7 +377,7 @@ def test_tags_are_replaced(tmp_path, mkdocs_file): testproject_path = setup_clean_mkdocs_folder(mkdocs_yml_path=f"tests/fixtures/{mkdocs_file}", output_path=tmp_path) setup_commit_history(testproject_path) result = build_docs_setup(testproject_path) - assert result.exit_code == 0, f"'mkdocs build' command failed with:\n{result.stdout}\nReplicate with 'cd {testproject_path} && uv run mkdocs build'" + assert result.exit_code == 0, f"'mkdocs build' command failed with:\n{result.stdout}\nReplicate with 'uv run mkdocs serve -f tests/fixtures/{mkdocs_file}'" plugin_config = get_plugin_config_from_mkdocs(str(testproject_path / "mkdocs.yml")) tags_file = testproject_path / "site/page_with_tag/index.html" From 9bcd563076fbf8dcbe8af58cec27ae40d58ed543 Mon Sep 17 00:00:00 2001 From: Tim Vink Date: Fri, 31 Oct 2025 16:05:53 +0100 Subject: [PATCH 2/6] Fix warning with uv dev deps --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d8bcaf8..760b3af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,8 +111,8 @@ target-version = "py310" # Always autofix fix = true -[tool.uv] -dev-dependencies = [ +[dependency-groups] +dev = [ "click>=8.1.8", "codecov>=2.1.13", "mkdocs-gen-files>=0.5.0", From da5a4b7c7077446f895b8d563d32e3454d1e81f4 Mon Sep 17 00:00:00 2001 From: Tim Vink Date: Fri, 31 Oct 2025 16:06:02 +0100 Subject: [PATCH 3/6] fix typo in docs --- docs/howto/specify-locale.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/howto/specify-locale.md b/docs/howto/specify-locale.md index 1123898..a23c039 100644 --- a/docs/howto/specify-locale.md +++ b/docs/howto/specify-locale.md @@ -1,6 +1,6 @@ # Specify a locale -`locale` is aa two letter [ISO639](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code (f.e. `en`) or [5-letter language code with added territory/region/country](https://www.mkdocs.org/user-guide/localizing-your-theme/#supported-locales) (`en_US`) that `git-revision-date-localized` uses to display dates in your preferred language. +`locale` is a two letter [ISO639](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) language code (f.e. `en`) or [5-letter language code with added territory/region/country](https://www.mkdocs.org/user-guide/localizing-your-theme/#supported-locales) (`en_US`) that `git-revision-date-localized` uses to display dates in your preferred language. For example: From 2a1ff1a4ac0f9eac3528381a2e5d29cd04517fd6 Mon Sep 17 00:00:00 2001 From: Tim Vink Date: Fri, 31 Oct 2025 16:10:19 +0100 Subject: [PATCH 4/6] improve test errors --- tests/test_builds.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_builds.py b/tests/test_builds.py index fac88d5..1f64bd1 100644 --- a/tests/test_builds.py +++ b/tests/test_builds.py @@ -320,7 +320,7 @@ def validate_mkdocs_file(temp_path: str, mkdocs_yml_file: str): testproject_path = setup_clean_mkdocs_folder(mkdocs_yml_path=mkdocs_yml_file, output_path=temp_path) setup_commit_history(testproject_path) result = build_docs_setup(testproject_path) - assert result.exit_code == 0, f"'mkdocs build' command failed with output:\n{result.stdout}\nReplicate with 'cd {testproject_path} && uv run mkdocs build'" + assert result.exit_code == 0, f"'mkdocs build' command failed with:\n{result.stdout}\nReplicate with 'uv run mkdocs serve -f {mkdocs_yml_file}'" # validate build with locale retrieved from mkdocs config file validate_build(testproject_path, plugin_config=get_plugin_config_from_mkdocs(mkdocs_yml_file)) @@ -648,7 +648,7 @@ def test_mkdocs_genfiles_plugin(tmp_path): ) setup_commit_history(testproject_path) result = build_docs_setup(testproject_path) - assert result.exit_code == 0, f"'mkdocs build' command failed with {result.stdout}\nReplicate with 'cd {testproject_path} && uv run mkdocs build'" + assert result.exit_code == 0, f"'mkdocs build' command failed with:\n{result.stdout}\nReplicate with 'uv run mkdocs serve -f tests/fixtures/mkdocs-gen-files/mkdocs.yml'" # validate the build plugin_config = get_plugin_config_from_mkdocs(str(testproject_path / "mkdocs.yml")) @@ -692,14 +692,14 @@ def test_monorepo_compat(tmp_path): testproject_path = setup_clean_mkdocs_folder("tests/fixtures/monorepo/mkdocs.yml", tmp_path) setup_commit_history(testproject_path) result = build_docs_setup(testproject_path) - assert result.exit_code == 0, f"'mkdocs build' command failed with:\n\n{result.stdout}\nReplicate with 'cd {testproject_path} && uv run mkdocs build'" + assert result.exit_code == 0, f"'mkdocs build' command failed with:\n{result.stdout}\nReplicate with 'uv run mkdocs serve -f tests/fixtures/monorepo/mkdocs.yml'" @pytest.mark.skipif(sys.platform.startswith("win"), reason="monorepo plugin did not work for me on windows (even without this plugin)") def test_monorepo_compat_reverse_order(tmp_path): testproject_path = setup_clean_mkdocs_folder("tests/fixtures/monorepo/mkdocs_reverse_order.yml", tmp_path) setup_commit_history(testproject_path) result = build_docs_setup(testproject_path) - assert result.exit_code == 0, f"'mkdocs build' command failed with:\n\n{result.stdout}\nReplicate with 'cd {testproject_path} && uv run mkdocs build'" + assert result.exit_code == 0, f"'mkdocs build' command failed with:\n{result.stdout}\nReplicate with 'uv run mkdocs serve -f tests/fixtures/monorepo/mkdocs_reverse_order.yml'" def test_genfiles_plugin(tmp_path): @@ -707,7 +707,7 @@ def test_genfiles_plugin(tmp_path): setup_commit_history(testproject_path) result = build_docs_setup(testproject_path) - assert result.exit_code == 0, f"'mkdocs build' command failed with:\n\n{result.stdout}\nReplicate with 'cd {testproject_path} && uv run mkdocs build'" + assert result.exit_code == 0, f"'mkdocs build' command failed with:\n{result.stdout}\nReplicate with 'uv run mkdocs serve -f tests/fixtures/basic_project/mkdocs_plugin_genfiles.yml'" page_with_tag = testproject_path / "site/foo/index.html" contents = page_with_tag.read_text(encoding="utf8") From 1e9c75297e822d6cffab4095a94402db0418cdbb Mon Sep 17 00:00:00 2001 From: Tim Vink Date: Fri, 31 Oct 2025 16:10:53 +0100 Subject: [PATCH 5/6] enable test with genfiles --- tests/test_builds.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_builds.py b/tests/test_builds.py index 1f64bd1..f7848ab 100644 --- a/tests/test_builds.py +++ b/tests/test_builds.py @@ -638,7 +638,6 @@ def test_low_fetch_depth(tmp_path, caplog): assert "Running on GitHub Actions might" in caplog.text -@pytest.mark.skip(reason="waiting for PR from mkdocs-genfiles-plugin to be merged first") def test_mkdocs_genfiles_plugin(tmp_path): """ Make sure the mkdocs-gen-files plugin works correctly. From 6c51d10d15cbb8130814b8ea75a928da4b598f5e Mon Sep 17 00:00:00 2001 From: Tim Vink Date: Fri, 31 Oct 2025 16:54:21 +0100 Subject: [PATCH 6/6] Move the - to _ conversion --- src/mkdocs_git_revision_date_localized_plugin/dates.py | 6 ++++++ src/mkdocs_git_revision_date_localized_plugin/plugin.py | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mkdocs_git_revision_date_localized_plugin/dates.py b/src/mkdocs_git_revision_date_localized_plugin/dates.py index f27e6fe..fa2c108 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/dates.py +++ b/src/mkdocs_git_revision_date_localized_plugin/dates.py @@ -22,6 +22,12 @@ def get_date_formats( assert time_zone is not None assert locale is not None + # Normalize locale for Babel: convert hyphens to underscores (e.g., pt-BR -> pt_BR) + # This is needed for compatibility with mkdocs-static-i18n and other plugins + # that may use hyphenated locale codes, while Babel expects underscores + if locale: + locale = str(locale).replace("-", "_") + utc_revision_date = datetime.fromtimestamp(int(unix_timestamp), tz=timezone.utc) loc_revision_date = utc_revision_date.replace(tzinfo=get_timezone("UTC")).astimezone(get_timezone(time_zone)) diff --git a/src/mkdocs_git_revision_date_localized_plugin/plugin.py b/src/mkdocs_git_revision_date_localized_plugin/plugin.py index 1f3497a..985a0a6 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/plugin.py +++ b/src/mkdocs_git_revision_date_localized_plugin/plugin.py @@ -291,12 +291,6 @@ def on_page_markdown(self, markdown: str, page: Page, config: config_options.Con if not locale: locale = self.config.get("locale") - # Normalize locale for Babel: convert hyphens to underscores (e.g., pt-BR -> pt_BR) - # This is needed for compatibility with mkdocs-static-i18n and other plugins - # that may use hyphenated locale codes, while Babel expects underscores - if locale: - locale = str(locale).replace("-", "_") - # Retrieve git commit timestamp # Except for generated pages (f.e. by mkdocs-gen-files plugin) if getattr(page.file, "generated_by", None):