Skip to content

Commit

Permalink
adapt README_{Country}.md stype name in localizedExtensions (#21486)
Browse files Browse the repository at this point in the history
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 <xiaolunwen@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
  • Loading branch information
3 people authored Oct 24, 2022
1 parent 49874b7 commit e1ce45e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions routers/web/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions routers/web/repo/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e1ce45e

Please sign in to comment.