From 437c018aaa1fbf6f71e439a451de41ab3907a3d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20L=C3=AA?= <8@tle.id.au> Date: Sun, 8 Feb 2026 02:39:12 +1100 Subject: [PATCH] Localize release note links on non-English releases pages The releases pages for non-English languages (ja, ko, uk, vi, zh_cn) always linked to the English (/en/) release posts because the post URL in _data/releases.yml is hardcoded to /en/. Add a localize_post_url Liquid filter plugin that checks whether a translated post exists for the current page language. If a translation is found, the link points to the localized post; otherwise it falls back to the original English URL. --- _plugins/localize_post_url.rb | 35 +++++++++++++++++++++++++++++++ ja/downloads/releases/index.md | 2 +- ko/downloads/releases/index.md | 2 +- uk/downloads/releases/index.md | 2 +- vi/downloads/releases/index.md | 2 +- zh_cn/downloads/releases/index.md | 2 +- 6 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 _plugins/localize_post_url.rb diff --git a/_plugins/localize_post_url.rb b/_plugins/localize_post_url.rb new file mode 100644 index 0000000000..3d17651264 --- /dev/null +++ b/_plugins/localize_post_url.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Jekyll + + # Provides a Liquid filter to resolve a localized version of a + # post URL when a translation exists for the given language. + # + # Falls back to the original (English) URL if no translation is found. + # + # Example: + # {{ release.post | localize_post_url: page.lang }} + # + module LocalizePostUrlFilter + + def localize_post_url(url, lang) + return url if lang.nil? || lang == "en" + + localized_url = url.sub(%r{\A/en/}, "/#{lang}/") + return url if localized_url == url + + site = @context.registers[:site] + + # Build a lookup set of all post URLs on first use (cached per site) + @post_urls ||= Set.new(site.posts.docs.map(&:url)) + + if @post_urls.include?(localized_url) + localized_url + else + url + end + end + end +end + +Liquid::Template.register_filter(Jekyll::LocalizePostUrlFilter) diff --git a/ja/downloads/releases/index.md b/ja/downloads/releases/index.md index 21eb6aad9d..41aef4c71b 100644 --- a/ja/downloads/releases/index.md +++ b/ja/downloads/releases/index.md @@ -28,6 +28,6 @@ lang: ja