Skip to content

Commit

Permalink
fix(plugin): fix handling of files with dotted suffixes, thx to @gnaegi
Browse files Browse the repository at this point in the history
closes issue #258
  • Loading branch information
ultrabug committed Sep 8, 2023
1 parent 4d3d338 commit 00df9ae
Show file tree
Hide file tree
Showing 19 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mkdocs_static_i18n/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ def create_i18n_file(

file_dest_path = Path(file.dest_path)
file_locale = default_language
file_localization = None

for language in all_languages:
if is_relative_to(file.src_path, language):
file_locale = language
file_localization = language
break
else:
# maybe the language folder is present BUT not configured in the plugin.languages yet
# so we use the locale regex to guess that it's a localization folder
maybe_file_locale = PurePath(file.src_path).parts[0]
if RE_LOCALE.match(maybe_file_locale):
file_locale = maybe_file_locale
file_localization = maybe_file_locale
break

# README.html should be renamed to index.html
Expand Down Expand Up @@ -83,6 +86,7 @@ def create_i18n_file(
file.alternates = {current_language: file}
file.locale = file_locale
file.locale_alternate_of = current_language
file.localization = file_localization

log.debug(f"reconfigure {file} from locale {file_locale}")

Expand Down
1 change: 1 addition & 0 deletions mkdocs_static_i18n/reconfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ def reconfigure_files(
# files when multiple languages are configured
if (
len(self.all_languages) > 1
and i18n_file.localization is not None
and i18n_dest_uris[i18n_file.dest_uri].locale == i18n_file.locale
):
raise Exception(
Expand Down
6 changes: 5 additions & 1 deletion mkdocs_static_i18n/suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def create_i18n_file(

file_dest_path = Path(file.dest_path)
file_locale = default_language
file_localization = None
locale_site_dir = current_language if current_language != default_language else ""

try:
Expand All @@ -47,12 +48,14 @@ def create_i18n_file(
file_dest_path = Path(f"{file_dest_path_no_suffix}{file_dest_path.suffix}")
# file name suffixed by locale, remove it
file.name = Path(file.name).stem
# store file localization
file_localization = file_locale
else:
file_locale = default_language
except IndexError:
pass

if config.use_directory_urls:
if config.use_directory_urls and file_localization:
if file_dest_path.parent != Path("."):
parent_dest_path_no_suffix = file_dest_path.parent.with_suffix("")
file_dest_path = parent_dest_path_no_suffix / file_dest_path.name
Expand Down Expand Up @@ -88,6 +91,7 @@ def create_i18n_file(
file.alternates = {current_language: file}
file.locale = file_locale
file.locale_alternate_of = current_language
file.localization = file_localization

log.debug(f"reconfigure {file} from locale {file_locale}")

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit 00df9ae

Please sign in to comment.