i18n
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Joakim Svensson 2025-07-18 08:48:21 +00:00
parent 1a18961362
commit 0e8ddb88e9
2 changed files with 44 additions and 11 deletions

View File

@ -7,20 +7,15 @@ clone:
depth: 0
steps:
- name: split-languages
- name: clean-language-blocks
image: python:3.11
commands:
- pip install -U pip
- python split_lang.py
- mkdir -p docs_sv/assets docs_sv/overrides docs_sv/stylesheets
- cp -r docs/assets docs_sv/assets || true
- cp -r docs/overrides docs_sv/overrides || true
- cp -r docs/stylesheets docs_sv/stylesheets || true
- rm -rf docs
- mv docs_sv docs
- mkdir -p docs/en
- cp -r docs_en/* docs/en/ || true
- python clean_language_blocks.py
- mkdir -p docs/assets docs/overrides docs/stylesheets
- cp -r docs_en/assets docs/assets || true
- cp -r docs_en/overrides docs/overrides || true
- cp -r docs_en/stylesheets docs/stylesheets || true
- name: build
image: squidfunk/mkdocs-material:7.1.9

38
clean_language_blocks.py Normal file
View File

@ -0,0 +1,38 @@
import os
import re
import shutil
SOURCE_DIR = "docs"
ENGLISH_DIR = "docs_en"
# Kopiera alla filer från docs/ till docs_en/
if os.path.exists(ENGLISH_DIR):
shutil.rmtree(ENGLISH_DIR)
shutil.copytree(SOURCE_DIR, ENGLISH_DIR)
def clean_file(path, keep_lang):
with open(path, "r", encoding="utf-8") as f:
content = f.read()
# Ta bort språkblock som inte ska vara kvar
if keep_lang == "sv":
content = re.sub(r":::\s*en\n.*?\n:::", "", content, flags=re.DOTALL)
elif keep_lang == "en":
content = re.sub(r":::\s*sv\n.*?\n:::", "", content, flags=re.DOTALL)
# Ta bort alla ::: lang-taggar
content = re.sub(r":::\s*(sv|en)", "", content)
content = re.sub(r":::", "", content)
with open(path, "w", encoding="utf-8") as f:
f.write(content.strip() + "\n")
# Rensa svenska versioner
for filename in os.listdir(SOURCE_DIR):
if filename.endswith(".md"):
clean_file(os.path.join(SOURCE_DIR, filename), keep_lang="sv")
# Rensa engelska versioner
for filename in os.listdir(ENGLISH_DIR):
if filename.endswith(".md"):
clean_file(os.path.join(ENGLISH_DIR, filename), keep_lang="en")