A Four-Language Static Site in Python: hreflang and Sitemap
By Nesim Razon, independent mobile developer · 2026-11-30
My website holds app pages, guides and articles in English, Turkish, Spanish and Portuguese. There is no site framework behind it, only Python scripts and static hosting. This is how the pieces fit together and which details mattered for search engines.

One command builds everything
A single script runs the others in a fixed order: the home page, the app detail pages, the guides, the blog, a small gift draw tool and finally the language splitter. If any step fails, the build stops there.
Before it starts, it deletes the generated language folders completely. That sounds drastic, but it guarantees that a renamed page does not leave a stale copy behind in the translated folders. The English pages at the root are not cleared this way. Everything in those folders can be produced again from the sources, so nothing of value is lost.
Two ways of holding translations
The older pages, the home page and the app pages, are first generated as one document that contains every language at once. Each translated element carries a language attribute. The splitter then makes one copy per language, removes the elements that belong to other languages and writes the result to its own address.
Articles and guides work the other way round. Each one is a Python dictionary with a block per language, and the generator writes each language straight to its own folder. This suits long text, because a translator sees one continuous article instead of paragraphs interleaved with three other languages.
Both end up in the same shape: English at the root and the other languages under their own folders. A page that exists in only one language, for example an app that is Turkish only, uses that language as its default.
Addresses people can read
Every language gets its own slug, written in that language. The Turkish article lives under a Turkish folder name with a Turkish address, not under an English one with a language code attached. The article module therefore stores four slugs, and the build refuses to guess them.
Internal links need care. A relative link that works on the English page can break one folder deeper. The splitter rewrites relative addresses into root based ones and, where a page exists in the same language, points the link there. A visitor reading Spanish stays in Spanish.
What goes into the head of each page
Search engines learn about the language versions from the page head. Each generated page carries:
- A canonical link to itself, so copies do not compete.
- One alternate link per available language, including the current one.
- A default alternate that points at English, or at the only language if there is no English.
- Social preview tags with the matching locale and, when it exists, a localised preview image.
- Structured data describing the article, its breadcrumbs and its questions and answers.
Titles longer than about sixty characters are shortened at a natural break such as a colon, and descriptions are cut at the end of a sentence. The visible heading keeps the full title.
A sitemap whose dates mean something
The sitemap lists every address with its alternates. The detail I care about is the last modified date. If every build stamped today on every page, the date would carry no information at all.
So the generator keeps a small file with a content hash per address. The date changes only when the hash changes. Pages that no longer exist on disk are dropped from the registry, and pages marked to stay out of search are not listed. At the moment the file holds a little over five hundred addresses.
Living with generated files in git
The output is committed, because the host serves the repository as it is. On Windows this creates noise: many files show as changed only because of line endings. Before committing I list the files whose content really differs, ignoring carriage returns, and add just those.
The same habit protects against surprises. If an article change shows modifications in pages that should not have moved, something in the generator has a side effect, and it is much easier to notice with a short list.
Tags and related articles without a database
Each article may carry up to three tags. A tag is a short key, and its visible name in each language lives in one table. If an article uses a key that is not in the table, the build stops with the article name, so a typing mistake cannot produce an untranslated label.
The article list shows the tags as buttons. A few lines of JavaScript hide the entries that do not match, and the chosen tag stays in the address after the hash, so a filtered list can be shared. Without JavaScript the full list is simply shown.
At the end of each article the generator picks up to six others: those about the same app come first, then the most recently added ones. It is a simple sort, computed at build time, and it gives every new article incoming links from older pages.
Videos that wait for their time
Many English articles have a narrated video. The generator keeps a small record of video identifiers and publication times, and places a click to load box in the article, so no video player is downloaded until a reader asks for it.
Videos are often uploaded well before their release. For those the box is generated but hidden, and a short script reveals it once the release time has passed. I do not need to rebuild the site on the day, and a reader never sees a player for a video that is still private.
Would I do it this way again
For a site of this size, yes. Adding an article means writing one module and adding its name to a list. The scripts are plain enough that I can read them a month later, and there is no dependency tree to update.
The cost is that every feature, from tags to video embeds, is something I write. If several people edited the site, or if the content changed many times a day, I would look for a ready made generator first. For one person publishing a few pieces at a time, a handful of scripts is easier to understand than a framework I would only half learn.
Frequently asked questions
What is hreflang for?
It tells search engines which addresses are the same page in other languages, so they can show the right one to each visitor.
Should every language have its own address?
Yes. Switching text with JavaScript on one address gives search engines only one version to index.
When should the sitemap date change?
Only when the content of that page changes. A date that changes on every build tells a crawler nothing.
Do I need a static site framework?
Not for a small site. A few scripts are enough if you are happy to write features yourself.
More from the blog
- What Stays Platform-Specific in a Kotlin Multiplatform App
- Declaring a Walking Game's Health Data in Play Console
- Blender From the Command Line: Pale Colours and Boolean Order
- Play Games Saved Games: A Merge That Never Goes Backwards
- From Blender Renders to Compose: Sprite Atlas and Layers
- A Preflight Script for iOS Builds: Save Cloud Mac Minutes