Skip to content

Commit

Permalink
add script to check which languages have complete translations for al…
Browse files Browse the repository at this point in the history
…l index_ strings
  • Loading branch information
mxmehl committed May 5, 2022
1 parent ad7c400 commit c11fc0a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ steps:
- apk add perl-yaml-tiny po4a
- cd site && po4a po/po4a.conf

# Create .status file for important i18n translation strings
- name: check_translations
image: python:3.10-alpine
commands:
- python3 check_translations.py site/i18n

# Build hugo
- name: hugo
image: plugins/hugo
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ site/content/tutorial.md
site/content/*/faq.md
site/content/*/spec.md
site/content/*/tutorial.md

# Translation status file created by check_translations.py
site/i18n/.status
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ COPY site/public/ /app/
FROM alpine:3 as dev-prep

# Dependencies
RUN apk --no-cache add bash perl-yaml-tiny po4a hugo
RUN apk --no-cache add bash perl-yaml-tiny po4a hugo python3

COPY . /app

Expand All @@ -42,6 +42,9 @@ RUN bash sync-docs.sh
# Run po4a for reuse-website po strings
RUN cd site/ && po4a po/po4a.conf

# Create .status file for important i18n translation strings
RUN python3 check_translations.py site/i18n

# Build hugo
RUN hugo -s site

Expand Down
56 changes: 56 additions & 0 deletions check_translations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Check which i18n translation files contain all index_ strings from EN"""

# SPDX-FileCopyrightText: Free Software Foundation Europe e.V.
#
# SPDX-License-Identifier: GPL-3.0-or-later

import json
import glob
import sys
import os

basedir = os.path.realpath(sys.argv[1])

# Load English strings in a dict
with open(f"{basedir}/en.json", encoding="UTF-8") as jsonfile:
en = json.load(jsonfile)

# Clear status file
with open(f"{basedir}/.status", 'w'): pass

# load all index strings
indexes = []
for k,v in en.items():
if k.startswith("index_"):
indexes.append(k)

# get all i18n string files
i18nfiles = glob.glob(f"{basedir}/*.json")

# Interate through translation files and check their completeness
for trans in i18nfiles:
lang = os.path.splitext(os.path.basename(trans))[0]

# skip English
if lang == "en":
continue

else:
# initialise key counter
transstrings = 0

# Load JSON file
with open(trans, encoding="UTF-8") as jsonfile:
trans = json.load(jsonfile)

# Check for all important strings whether they exist in translation
for key in indexes:
if key in trans:
transstrings += 1

# Check if same amount of strings available
if transstrings == len(indexes):
with open(f"{basedir}/.status", "a") as statusfile:
statusfile.write(f"{lang}\n")
else:
print(f"[WARN] Important keys for \"{lang}\" not complete!")

0 comments on commit c11fc0a

Please sign in to comment.