[lxc-devel] [linuxcontainers.org/master] Logic to detect out of date translations #415
anirudh-goyal on Github
lxc-bot at linuxcontainers.org
Fri Oct 23 09:29:50 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1064 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201023/657d6265/attachment.bin>
-------------- next part --------------
From 688dabfcb3734ffa56abfad8a4d51ff02acee11d Mon Sep 17 00:00:00 2001
From: anirudh-goyal <anirudhgoyal at utexas.edu>
Date: Fri, 23 Oct 2020 14:49:05 +0530
Subject: [PATCH] - Added support for comparing a translated markdown file and
its matching source file based on their last modified times. - If the
translated file is more than a day older than source file, a warning is
displayed with a link to the English version. Signed-off-by: Anirudh Goyal
<anirudhgoyal at utexas.edu>
---
generate | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/generate b/generate
index 365cf2c..0f104a4 100755
--- a/generate
+++ b/generate
@@ -214,6 +214,24 @@ def download_sort_key(download_name):
# Treat the entire filename as tokens delimited by dash or dot.
return [token_key(token) for token in re.split(r'[-.]', download_name)]
+def is_translated_md(language_prefix, md_path):
+ language = language_prefix[1:] # removing the '/'
+ md_file = md_path.split('/')[-1] # content/cgmanager/contribute.ru.md -> contribute.ru.md
+ period_split = md_file.split('.')
+ if len(period_split) > 2 and period_split[1] == language:
+ return True
+ return False
+
+def is_translated_outdated(translated_file_path):
+ source_file_path = translated_file_path[:-6] + ".md" # cgmanager/contribute.ru.md -> cgmanager/contribute.md
+ BUFFER = 86400 # 1 day
+ if (os.path.getmtime(source_file_path) - os.path.getmtime(translated_file_path)) > BUFFER:
+ return True
+ return False
+
+def add_translation_warning(md_content, page_raw_path):
+ translation_warning = f"### Note: This translated page may be outdated. Please visit the [English version]({page_raw_path}) for the up to date content.\n"
+ return translation_warning + md_content
def gen_page(entry, override, prefix, **variables):
item = dict(entry)
@@ -259,13 +277,22 @@ def gen_page(entry, override, prefix, **variables):
content = fd.read()
elif item['generator'] == "markdown":
template = "markdown-page.tpl.html"
- with open(content_path(item['meta']['input']), "r") as fd:
- content = md2html(fd.read())
+ md_path = content_path(item['meta']['input'])
+ with open(md_path, "r") as fd:
+ md_content = fd.read()
+ if prefix and is_translated_md(prefix, md_path) and is_translated_outdated(md_path):
+ md_content = add_translation_warning(md_content, page_raw_path)
+ content = md2html(md_content)
+
elif item['generator'] == "downloads":
# Support a markdown description before the download table
if "input" in item['meta']:
- with open(content_path(item['meta']['input']), "r") as fd:
- content = md2html(fd.read())
+ md_path = content_path(item['meta']['input'])
+ with open(md_path, "r") as fd:
+ md_content = fd.read()
+ if prefix and is_translated_md(prefix, md_path) and is_translated_outdated(md_path):
+ md_content = add_translation_warning(md_content, page_raw_path)
+ content = md2html(md_content)
downloads = []
download_path = item['meta']['dir'].lstrip("/")
More information about the lxc-devel
mailing list