i18n
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c9bd862714
commit
00c0b23494
|
@ -2,31 +2,35 @@ import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
SOURCE_DIR = "docs"
|
SOURCE_DIR = "docs"
|
||||||
OUTPUT_DIRS = {
|
OUTPUT_DIRS = {"sv": "docs_sv", "en": "docs_en"}
|
||||||
"sv": "docs_sv",
|
|
||||||
"en": "docs_en"
|
|
||||||
}
|
|
||||||
|
|
||||||
lang_block_re = re.compile(r":::\s*(sv|en)\n(.*?)\n:::", re.DOTALL)
|
lang_block_re = re.compile(r":::\s*(sv|en)\n(.*?)\n:::", re.DOTALL | re.IGNORECASE)
|
||||||
|
|
||||||
def split_content_by_language(content):
|
def split_content_by_language(content):
|
||||||
blocks = {"sv": "", "en": ""}
|
blocks = {"sv": "", "en": ""}
|
||||||
|
neutral_parts = []
|
||||||
pos = 0
|
pos = 0
|
||||||
|
|
||||||
matches = list(lang_block_re.finditer(content))
|
matches = list(lang_block_re.finditer(content))
|
||||||
|
|
||||||
|
if not matches:
|
||||||
|
return {"sv": content, "en": ""}
|
||||||
|
|
||||||
for match in matches:
|
for match in matches:
|
||||||
start, end = match.span()
|
start, end = match.span()
|
||||||
lang, text = match.groups()
|
lang, text = match.groups()
|
||||||
neutral = content[pos:start]
|
neutral = content[pos:start]
|
||||||
for l in blocks:
|
neutral_parts.append(neutral)
|
||||||
blocks[l] += neutral
|
blocks[lang.lower()] += text.strip() + "\n\n"
|
||||||
blocks[lang] += text.strip() + "\n\n"
|
|
||||||
pos = end
|
pos = end
|
||||||
|
|
||||||
# Tail inkluderas i båda språkversionerna
|
# Innehåll efter sista språkblock
|
||||||
tail = content[pos:]
|
neutral_parts.append(content[pos:])
|
||||||
|
|
||||||
|
# Lägg neutral text i båda
|
||||||
|
tail = ''.join(neutral_parts)
|
||||||
for l in blocks:
|
for l in blocks:
|
||||||
blocks[l] += tail
|
blocks[l] = tail + blocks[l]
|
||||||
|
|
||||||
return blocks
|
return blocks
|
||||||
|
|
||||||
|
@ -46,5 +50,4 @@ for filename in os.listdir(SOURCE_DIR):
|
||||||
f.write(text.strip())
|
f.write(text.strip())
|
||||||
print(f"✔ Skrev {lang}/{filename}")
|
print(f"✔ Skrev {lang}/{filename}")
|
||||||
else:
|
else:
|
||||||
print(f"⚠️ Hoppade över {lang}/{filename} (tom)")
|
print(f"⚠️ Skippade {lang}/{filename} (tom)")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue