Incremental translation with translation by file name

Hey,

I want to incrementally translate my website. If a post is not translated, the content should be displayed in the default language instead.

Using mounts is an often suggested solution: Do all page bundles need localized copies once you add a new language? - #12 by jmooring

Is there an alternative in case I want to keep using filenames with language codes? (Multilingual mode)

Thank you very much in advance!

You can use mounts to fill in the gaps when translating by file name, but you must exclude the language identifier from the filename for content files in the default language. For example:

content/
β”œβ”€β”€ posts/
β”‚   β”œβ”€β”€ _index.de.md
β”‚   β”œβ”€β”€ _index.md    <-- excludes language identifier
β”‚   β”œβ”€β”€ post-1.de.md
β”‚   β”œβ”€β”€ post-1.md    <-- excludes language identifier
β”‚   └── post-2.md    <-- excludes language identifier
β”œβ”€β”€ _index.de.md
└── _index.md        <-- excludes language identifier

Then you can do this:

[[module.mounts]]
source = 'content'
target = 'content'

# Fills gaps in `de` with content from default language
[[module.mounts]]
source = 'content'
target = 'content'
lang = 'de'

# Fills gaps in `fr` with content from default language
[[module.mounts]]
source = 'content'
target = 'content'
lang = 'fr'

The only limitation with this approach (when compared to translating by directory) is that you are always filling in the gaps with content from the default content language… you cannot cascade β€œup” from one language to the next.

Try it:

git clone --single-branch -b hugo-forum-topic-54270 https://github.com/jmooring/hugo-testing hugo-forum-topic-54270
cd hugo-forum-topic-54270
hugo server
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.