From e1ce45eabf25175d06472fadd01261548a48f1fd Mon Sep 17 00:00:00 2001 From: a1012112796 <1012112796@qq.com> Date: Mon, 24 Oct 2022 14:12:15 +0800 Subject: [PATCH] adapt README_{Country}.md stype name in localizedExtensions (#21486) This stype name is also used in many repos, example: [``README_ZH.md``](https://github.com/go-gitea/gitea/blob/main/README_ZH.md) Signed-off-by: a1012112796 <1012112796@qq.com> Co-authored-by: Lunny Xiao Co-authored-by: zeripath --- routers/web/repo/view.go | 4 ++-- routers/web/repo/view_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 8cb45f623dd97..d35ec48df048d 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -151,8 +151,8 @@ func localizedExtensions(ext, languageCode string) (localizedExts []string) { if strings.Contains(lowerLangCode, "-") { underscoreLangCode := strings.ReplaceAll(lowerLangCode, "-", "_") indexOfDash := strings.Index(lowerLangCode, "-") - // e.g. [.zh-cn.md, .zh_cn.md, .zh.md, .md] - return []string{lowerLangCode + ext, underscoreLangCode + ext, lowerLangCode[:indexOfDash] + ext, ext} + // e.g. [.zh-cn.md, .zh_cn.md, .zh.md, _zh.md, .md] + return []string{lowerLangCode + ext, underscoreLangCode + ext, lowerLangCode[:indexOfDash] + ext, "_" + lowerLangCode[1:indexOfDash] + ext, ext} } // e.g. [.en.md, .md] diff --git a/routers/web/repo/view_test.go b/routers/web/repo/view_test.go index 9d5a88fca412b..803906b217786 100644 --- a/routers/web/repo/view_test.go +++ b/routers/web/repo/view_test.go @@ -38,19 +38,19 @@ func Test_localizedExtensions(t *testing.T) { name: "With region - lowercase", languageCode: "en-us", ext: ".md", - wantLocalizedExts: []string{".en-us.md", ".en_us.md", ".en.md", ".md"}, + wantLocalizedExts: []string{".en-us.md", ".en_us.md", ".en.md", "_en.md", ".md"}, }, { name: "With region - uppercase", languageCode: "en-CA", ext: ".MD", - wantLocalizedExts: []string{".en-ca.MD", ".en_ca.MD", ".en.MD", ".MD"}, + wantLocalizedExts: []string{".en-ca.MD", ".en_ca.MD", ".en.MD", "_en.MD", ".MD"}, }, { name: "With region - all uppercase", languageCode: "ZH-TW", ext: ".md", - wantLocalizedExts: []string{".zh-tw.md", ".zh_tw.md", ".zh.md", ".md"}, + wantLocalizedExts: []string{".zh-tw.md", ".zh_tw.md", ".zh.md", "_zh.md", ".md"}, }, } for _, tt := range tests {