Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/howto/specify-locale.md
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/mkdocs_git_revision_date_localized_plugin/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 7 additions & 7 deletions tests/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -637,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.
Expand All @@ -647,7 +647,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"))
Expand Down Expand Up @@ -691,22 +691,22 @@ 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):
testproject_path = setup_clean_mkdocs_folder("tests/fixtures/basic_project/mkdocs_plugin_genfiles.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/basic_project/mkdocs_plugin_genfiles.yml'"

page_with_tag = testproject_path / "site/foo/index.html"
contents = page_with_tag.read_text(encoding="utf8")
Expand Down