mirror of
https://github.com/gcushen/hugo-academic.git
synced 2025-07-26 19:15:16 +02:00
i18n: sync language packs against master to fix missing interface text
The structure of some language packs is very outdated, leading to missing user interface text when using these packs. Developed a Python script to sync the structure of all language packs against the master pack (English) so that each pack has the latest set of localisation strings. Note that synced items will still need translating, this commit just ensures that all language packs have the same structure. Fix #1062
This commit is contained in:
parent
88e0459e68
commit
93150a55e9
21 changed files with 1054 additions and 1507 deletions
52
scripts/sync_i18n.py
Normal file
52
scripts/sync_i18n.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# Sync Language Packs
|
||||
# Script to synchronize each language pack's items against Academic's master pack (English).
|
||||
# https://sourcethemes.com/academic/
|
||||
#
|
||||
# Prerequisites: pip3 install PyYAML
|
||||
#
|
||||
# TODO: Switch from PyYAML to Ruamel in order to load/dump comments -
|
||||
# see https://stackoverflow.com/questions/47382227/python-yaml-update-preserving-order-and-comments
|
||||
|
||||
import copy
|
||||
from pathlib import Path
|
||||
import yaml
|
||||
|
||||
I18N_PATH = Path(__file__).resolve().parent.parent.joinpath('i18n')
|
||||
MASTER_PACK = I18N_PATH.joinpath('en.yaml')
|
||||
|
||||
|
||||
# Load master language pack (English).
|
||||
with open(MASTER_PACK) as f:
|
||||
master_map = yaml.safe_load(f)
|
||||
# if (DEBUG)
|
||||
# print(master_map)
|
||||
|
||||
# Iterate over each child language pack.
|
||||
cnt = 0
|
||||
for filename in Path(I18N_PATH).glob("*.yaml"):
|
||||
if filename.stem != 'en':
|
||||
i18n_file = I18N_PATH.joinpath(filename)
|
||||
print(f"Processing {i18n_file} ...")
|
||||
|
||||
# Load a child language pack.
|
||||
with open(i18n_file) as f:
|
||||
child_map = yaml.safe_load(f)
|
||||
|
||||
# Synchronize the language pack's structure against the master language pack.
|
||||
tmp_map = copy.deepcopy(master_map) # Make a temporary deep copy of the master map (list of objects).
|
||||
master_index = 0
|
||||
for master_item in master_map:
|
||||
translation = next((item['translation'] for item in child_map if item['id'] == master_item['id']),
|
||||
master_item['translation'])
|
||||
tmp_map[master_index]['translation'] = translation
|
||||
master_index += 1
|
||||
|
||||
# Write the synced language pack to file.
|
||||
with open(i18n_file, 'w') as f:
|
||||
yaml.dump(tmp_map, f, allow_unicode=True, width=float("inf")) # PyYAML will break lines unless a large column width is set.
|
||||
cnt += 1
|
||||
|
||||
# Print results.
|
||||
print(f"{cnt} child language packs successfully synchronized!")
|
13
scripts/update_bootstrap.sh
Normal file
13
scripts/update_bootstrap.sh
Normal file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
# Script to copy Bootstrap files into project after running `npm install` to download Bootstrap.
|
||||
|
||||
ASSETS_JS_DIR="assets/js/vendor/"
|
||||
ASSETS_SCSS_DIR="assets/sass/vendor/"
|
||||
|
||||
mkdir -p $ASSETS_SCSS_DIR/bootstrap/
|
||||
|
||||
cp node_modules/bootstrap/dist/js/bootstrap.min.js $ASSETS_JS_DIR
|
||||
cp -r node_modules/bootstrap/scss/* $ASSETS_SCSS_DIR/bootstrap/
|
||||
|
||||
# cp node_modules/jquery/dist/jquery.min.js $ASSETS_JS_DIR
|
||||
# cp node_modules/popper.js/dist/umd/popper.min.js $ASSETS_JS_DIR
|
Loading…
Add table
Add a link
Reference in a new issue