Skip to content

Commit

Permalink
feat(reconfigure): allow the default language to use localized files …
Browse files Browse the repository at this point in the history
…or not wrt issue #262 (#269)
  • Loading branch information
ultrabug committed Oct 4, 2023
1 parent 77ed64a commit 96554ac
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions mkdocs_static_i18n/reconfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,18 +543,24 @@ def reconfigure_files(
# use the file since its locale is our current build language
if i18n_file.locale == self.current_language:
i18n_dest_uris[i18n_file.dest_uri] = i18n_file
log.debug(f"Use {i18n_file.locale} {i18n_file}")
log.debug(
f"Use {i18n_file.locale} {i18n_file.localization} {i18n_file}"
)
# if locale is the default language AND default language fallback is enabled
# we are using a file that is not really our locale
elif (
self.config.fallback_to_default is True
and i18n_file.locale == self.default_language
):
i18n_dest_uris[i18n_file.dest_uri] = i18n_file
log.debug(f"Use default {i18n_file.locale} {i18n_file}")
log.debug(
f"Use default {i18n_file.locale} {i18n_file.localization} {i18n_file}"
)
i18n_alternate_dest_uris[i18n_file.dest_uri].append(file)
else:
log.debug(f"Ignore {i18n_file.locale} {i18n_file}")
log.debug(
f"Ignore {i18n_file.locale} {i18n_file.localization} {i18n_file}"
)
i18n_alternate_dest_uris[i18n_file.dest_uri].append(file)

# we've seen that file already
Expand All @@ -564,7 +570,7 @@ def reconfigure_files(
# users should not add default non suffixed/folder files + suffixed/folder
# files when multiple languages are configured
if (
len(self.all_languages) > 1
len(self.build_languages) > 1
and i18n_file.localization is not None
and i18n_dest_uris[i18n_file.dest_uri].locale == i18n_file.locale
):
Expand All @@ -574,9 +580,13 @@ def reconfigure_files(
f"'{i18n_dest_uris[i18n_file.dest_uri].src_uri}' but not both"
)
i18n_dest_uris[i18n_file.dest_uri] = i18n_file
log.debug(f"Use localized {i18n_file.locale} {i18n_file}")
log.debug(
f"Use localized {i18n_file.locale} {i18n_file.localization} {i18n_file}"
)
else:
log.debug(f"Ignore {i18n_file.locale} {i18n_file}")
log.debug(
f"Ignore {i18n_file.locale} {i18n_file.localization} {i18n_file}"
)
i18n_alternate_dest_uris[i18n_file.dest_uri].append(file)

# user provided asset
Expand All @@ -587,7 +597,9 @@ def reconfigure_files(
# use the file since its locale is our current build language
if i18n_file.locale == self.current_language:
i18n_dest_uris[i18n_file.dest_uri] = i18n_file
log.debug(f"Use asset {i18n_file.locale} {i18n_file}")
log.debug(
f"Use asset {i18n_file.locale} {i18n_file.localization} {i18n_file}"
)
# if locale is the default language AND default language fallback is enabled
# we are using a file that is not really our locale
elif (
Expand All @@ -602,14 +614,18 @@ def reconfigure_files(
mkdocs_config,
)
i18n_dest_uris[i18n_file.dest_uri] = i18n_asset
log.debug(f"Use default asset {i18n_asset.locale} {i18n_asset}")
log.debug(
f"Use asset default {i18n_asset.locale} {i18n_file.localization} {i18n_asset}"
)

# we've seen that file already
else:
# override it only if this is our language
if i18n_file.locale == self.current_language:
if i18n_file.localization == self.current_language:
i18n_dest_uris[i18n_file.dest_uri] = i18n_file
log.debug(f"Use localized asset {i18n_file.locale} {i18n_file}")
log.debug(
f"Use asset localized {i18n_file.locale} {i18n_file.localization} {i18n_file}"
)

# theme (and overrides) files
elif not file.is_documentation_page():
Expand All @@ -620,7 +636,7 @@ def reconfigure_files(
# populate the resulting Files and keep track of all the alternates
# that will be used by the sitemap.xml template
for file in i18n_dest_uris.values():
log.debug(f"Selected {file.locale} {file}")
log.debug(f"Selected {file.locale} {file.localization} {file}")
i18n_files.append(file)

# build the alternates for all the Files
Expand Down

0 comments on commit 96554ac

Please sign in to comment.