Skip to content

Commit 82b6a8c

Browse files
committed
Cleaning usuless modifications
1 parent ef6aff2 commit 82b6a8c

File tree

1 file changed

+25
-41
lines changed
  • mkdocs_git_revision_date_localized_plugin

1 file changed

+25
-41
lines changed

mkdocs_git_revision_date_localized_plugin/plugin.py

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class GitRevisionDateLocalizedPlugin(BasePlugin):
2020
)
2121

2222
def __init__(self):
23-
self.locale = "en"
2423
self.util = Util()
2524

2625
def on_config(self, config: config_options.Config) -> dict:
@@ -41,44 +40,26 @@ def on_config(self, config: config_options.Config) -> dict:
4140

4241
# Get locale settings - might be added in future mkdocs versions
4342
# see: https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/issues/24
44-
mkdocs_locale = config.get(
45-
"locale", None
46-
)
43+
mkdocs_locale = config.get("locale", None)
4744

4845
# Get locale from plugin configuration
4946
plugin_locale = self.config.get("locale", None)
5047

5148
# theme locale
5249
if "theme" in config and "locale" in config.get("theme"):
5350
custom_theme = config.get("theme")
54-
if isinstance(custom_theme, Theme):
55-
theme_locale = custom_theme._vars.get("locale")
56-
logging.debug(
57-
"Locale '%s' extracted from the custom theme: '%s'"
58-
% (theme_locale, custom_theme.name)
59-
)
60-
elif isinstance(custom_theme, dict):
61-
theme_locale = custom_theme.get("locale")
62-
logging.debug(
63-
"Locale '%s' extracted from the custom theme: '%s'"
64-
% (theme_locale, custom_theme.get("name"))
65-
)
51+
theme_locale = custom_theme._vars.get("locale")
52+
logging.debug(
53+
"Locale '%s' extracted from the custom theme: '%s'"
54+
% (theme_locale, custom_theme.name)
55+
)
6656
elif "theme" in config and "language" in config.get("theme"):
6757
custom_theme = config.get("theme")
68-
if isinstance(custom_theme, Theme):
69-
theme_locale = custom_theme._vars.get("language")
70-
logging.debug(
71-
"Locale '%s' extracted from the custom theme: '%s'"
72-
% (theme_locale, custom_theme.name)
73-
)
74-
elif isinstance(custom_theme, dict):
75-
theme_locale = custom_theme.get("language")
76-
logging.debug(
77-
"Locale '%s' extracted from the custom theme: '%s'"
78-
% (theme_locale, custom_theme.get("name"))
79-
)
80-
else:
81-
pass
58+
theme_locale = custom_theme._vars.get("language")
59+
logging.debug(
60+
"Locale '%s' extracted from the custom theme: '%s'"
61+
% (theme_locale, custom_theme.name)
62+
)
8263

8364
else:
8465
theme_locale = None
@@ -88,25 +69,25 @@ def on_config(self, config: config_options.Config) -> dict:
8869

8970
# First prio: plugin locale
9071
if plugin_locale:
91-
self.locale = plugin_locale
92-
logging.debug("Using locale from plugin configuration: %s" % self.locale)
72+
locale_set = plugin_locale
73+
logging.debug("Using locale from plugin configuration: %s" % locale_set)
9374
# Second prio: theme locale
9475
elif theme_locale:
95-
self.locale = theme_locale
76+
locale_set = theme_locale
9677
logging.debug(
9778
"Locale not set in plugin. Fallback to theme configuration: %s"
98-
% self.locale
79+
% locale_set
9980
)
10081
# Third prio is mkdocs locale (which might be added in the future)
10182
elif mkdocs_locale:
102-
self.locale = mkdocs_locale
103-
logging.debug("Using locale from mkdocs configuration: %s" % self.locale)
83+
locale_set = mkdocs_locale
84+
logging.debug("Using locale from mkdocs configuration: %s" % locale_set)
10485
else:
105-
self.locale = "en"
106-
logging.debug("No locale set. Fallback to: %s" % self.locale)
86+
locale_set = "en"
87+
logging.debug("No locale set. Fallback to: %s" % locale_set)
10788

10889
# set locale also in plugin configuration
109-
self.config["locale"] = self.locale
90+
self.config["locale"] = locale_set
11091

11192
return config
11293

@@ -130,7 +111,7 @@ def on_post_page(self, output_content: str, **kwargs) -> str:
130111
str: output of rendered template as string
131112
"""
132113

133-
if self.config["type"] != "timeago":
114+
if self.config.get("type") != "timeago":
134115
return output_content
135116

136117
extra_js = """
@@ -170,7 +151,7 @@ def on_page_markdown(
170151

171152
revision_dates = self.util.get_revision_date_for_file(
172153
path=page.file.abs_src_path,
173-
locale=self.locale,
154+
locale=self.config.get("locale", "en"),
174155
fallback_to_build_date=self.config.get("fallback_to_build_date"),
175156
)
176157
revision_date = revision_dates[self.config["type"]]
@@ -198,3 +179,6 @@ def on_page_markdown(
198179
assert plg.locale == "en"
199180
assert isinstance(plg.config, dict)
200181
assert plg.config == {}
182+
183+
plg.load_config({"locale": "fr"})
184+
print(plg.config)

0 commit comments

Comments
 (0)