The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/linuxcontainers.org/pull/456
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === - Added support for comparing a translated markdown file and its matching source file based on their last modified times. - Translated files are detected based on the `language_prefix` and if they're of the form `foo.<language_prefix>.md`. Its corresponding source file is then `foo.md`. - If the translated file is more than a day older than source file, a warning is displayed with a link to the English version. - To display the warning, the markdown content is changed in Python (without changing the actual markdown file) before calling `md2html` . Example warning:  Signed-off-by: Anirudh Goyal <anirudhgo...@utexas.edu>
From 688dabfcb3734ffa56abfad8a4d51ff02acee11d Mon Sep 17 00:00:00 2001 From: anirudh-goyal <anirudhgo...@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 <anirudhgo...@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("/")
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel