mkdocs-static-i18n: Folder structure: get_file_from_path() returns wrong files and is_index() broken
Hi,
I know it is clearly stated that the folder structure is not as mature as the suffix one, but I’ve been experimenting with the folder structure lately, as it would allow me to do two things:
- use a second mkdocs.yml with a different 
default_languageset - and only build the default language in the root folder (without redundant copy) So one configuration will build / (en) and /de (not /en) and the other would build / (de) and /en (not /de).
 
Furthermore, I also would like to host non localized images/videos just once as described here, but couldn’t get it to not save redundant copies of said images/videos, yet.
I made a new branch for my configuration here. With the current mkdocs(1.5.2) and mkdocs-static-i18n (0.56) the project builds, but the menu structure is wrong in two ways:
- One index file (colors/index.md) is returned as index.md by get_file_from_path(). This way we got a double entry in nav of the site and this breaks the navigation. I worked around with this patch, but I certainly don’t fully understand what the code does or if this breaks something else:
 
--- C:/Users/Rene/AppData/Local/Programs/Python/Python38/Lib/site-packages/mkdocs_static_i18n/folder_structure.py.org	Sun Aug  6 17:05:26 2023
+++ C:/Users/Rene/AppData/Local/Programs/Python/Python38/Lib/site-packages/mkdocs_static_i18n/folder_structure.py	Sun Aug  6 17:03:55 2023
@@ -55,10 +55,7 @@
             expected_src_path,
             expected_src_path.relative_to(root_folder),
             Path(self.locale) / Path(expected_src_path),
-            Path(self.locale) / Path(expected_src_path.relative_to(root_folder)),
             Path(self.default_locale) / Path(expected_src_path),
-            Path(self.default_locale)
-            / Path(expected_src_path.relative_to(root_folder)),
         ]
         for src_path in filter(lambda s: Path(s) in expected_src_paths, self.src_paths):
             return self.src_paths.get(os.path.normpath(src_path))
- The index files are not marked as such by the page.is_index() because the “file.name” is “index.md” (and not “index”). I intervened with the patch (copied from suffix structure):
 
--- C:/Users/Rene/AppData/Local/Programs/Python/Python38/Lib/site-packages/mkdocs_static_i18n/folder_structure.py.org	Sun Aug  6 17:05:26 2023
+++ C:/Users/Rene/AppData/Local/Programs/Python/Python38/Lib/site-packages/mkdocs_static_i18n/folder_structure.py	Sun Aug  6 17:03:55 2023
@@ -111,8 +108,8 @@
         self.locale_suffix = None
         self.root_folder = Path(file_from.src_path).parts[0]
 
-        # the name
-        self.name = Path(self.initial_src_path).name
+        # the name without any suffix
+        self.name = self._get_name()
         self.dest_name = self.name
 
         if self.root_folder not in self.all_languages:
Also, i18n_page_file_locale doesn’t seem to work within folder structure.
Anyway, thank you for this great plugin, it is very useful.
About this issue
- Original URL
 - State: closed
 - Created a year ago
 - Comments: 17 (10 by maintainers)
 
Yes, just ping me. I’d be glad if I can help by testing.