@@ -20,7 +20,6 @@ class GitRevisionDateLocalizedPlugin(BasePlugin):
20
20
)
21
21
22
22
def __init__ (self ):
23
- self .locale = "en"
24
23
self .util = Util ()
25
24
26
25
def on_config (self , config : config_options .Config ) -> dict :
@@ -41,44 +40,26 @@ def on_config(self, config: config_options.Config) -> dict:
41
40
42
41
# Get locale settings - might be added in future mkdocs versions
43
42
# 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 )
47
44
48
45
# Get locale from plugin configuration
49
46
plugin_locale = self .config .get ("locale" , None )
50
47
51
48
# theme locale
52
49
if "theme" in config and "locale" in config .get ("theme" ):
53
50
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
+ )
66
56
elif "theme" in config and "language" in config .get ("theme" ):
67
57
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
+ )
82
63
83
64
else :
84
65
theme_locale = None
@@ -88,25 +69,25 @@ def on_config(self, config: config_options.Config) -> dict:
88
69
89
70
# First prio: plugin locale
90
71
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 )
93
74
# Second prio: theme locale
94
75
elif theme_locale :
95
- self . locale = theme_locale
76
+ locale_set = theme_locale
96
77
logging .debug (
97
78
"Locale not set in plugin. Fallback to theme configuration: %s"
98
- % self . locale
79
+ % locale_set
99
80
)
100
81
# Third prio is mkdocs locale (which might be added in the future)
101
82
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 )
104
85
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 )
107
88
108
89
# set locale also in plugin configuration
109
- self .config ["locale" ] = self . locale
90
+ self .config ["locale" ] = locale_set
110
91
111
92
return config
112
93
@@ -130,7 +111,7 @@ def on_post_page(self, output_content: str, **kwargs) -> str:
130
111
str: output of rendered template as string
131
112
"""
132
113
133
- if self .config [ "type" ] != "timeago" :
114
+ if self .config . get ( "type" ) != "timeago" :
134
115
return output_content
135
116
136
117
extra_js = """
@@ -170,7 +151,7 @@ def on_page_markdown(
170
151
171
152
revision_dates = self .util .get_revision_date_for_file (
172
153
path = page .file .abs_src_path ,
173
- locale = self .locale ,
154
+ locale = self .config . get ( " locale" , "en" ) ,
174
155
fallback_to_build_date = self .config .get ("fallback_to_build_date" ),
175
156
)
176
157
revision_date = revision_dates [self .config ["type" ]]
@@ -198,3 +179,6 @@ def on_page_markdown(
198
179
assert plg .locale == "en"
199
180
assert isinstance (plg .config , dict )
200
181
assert plg .config == {}
182
+
183
+ plg .load_config ({"locale" : "fr" })
184
+ print (plg .config )
0 commit comments