1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00
lvgl/docs/add_translation.py
100ask fdc26f6459
docs: chinese translation link only on the homepage (#7370)
Co-authored-by: Yobe Zhou <33565334+YobeZhou@users.noreply.github.com>
Co-authored-by: Victor Wheeler <vwheeler63@users.noreply.github.com>
2024-12-03 13:07:23 +01:00

51 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import os
"""
Please add the translation language you want to add here, while also modifying the variable URL_BASE in _ext/link_roles.py
For example:
LANGUAGE = ':link_to_translation:`zh_CN:[中文]`\t' + \
':link_to_translation:`en:[English]`\t' + \
'\n\n'
URL_BASE = {
"zh_CN": "https://lvgl.100ask.net/",
"en": "https://docs.lvgl.io/"
}
"""
LANGUAGE = ':link_to_translation:`zh_CN:[中文]`\t' + \
'\n\n'
def find_files(dir_path, suffix):
files = []
for root, _, filenames in os.walk(dir_path):
for filename in filenames:
if filename.endswith(suffix):
files.append(os.path.join(root, filename))
return files
def exec(temp_directory):
"""
files = find_files(temp_directory, '.rst')
for rst_file in files:
with open(rst_file, 'r+', encoding='utf-8') as f:
content = f.read()
f.seek(0, 0)
f.write(LANGUAGE + content)
"""
rst_file = os.path.join(temp_directory, 'index.rst')
with open(rst_file, 'r+', encoding='utf-8') as f:
content = f.read()
f.seek(0, 0)
f.write(LANGUAGE + content)