Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt README_{Country}.md stype name in localizedExtensions #21486

Merged
merged 30 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
68193c6
adapt README_{Contry}.md stype name in localizedExtensions
a1012112796 Oct 17, 2022
9cb175e
fix test
a1012112796 Oct 17, 2022
e257383
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 17, 2022
c6b552d
Merge branch 'main' into zzc/dev/readme_link
a1012112796 Oct 18, 2022
54db32c
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 18, 2022
acb6eb2
Merge branch 'main' into zzc/dev/readme_link
a1012112796 Oct 18, 2022
428321d
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 18, 2022
181d6b5
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 18, 2022
338bd3d
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 18, 2022
ed935b2
Update routers/web/repo/view.go
a1012112796 Oct 19, 2022
50bc00e
Merge branch 'main' into zzc/dev/readme_link
a1012112796 Oct 19, 2022
8ecc357
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 19, 2022
b3f9f26
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 19, 2022
9618c87
make fmt
a1012112796 Oct 19, 2022
f67b89f
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 19, 2022
fbe9a2b
Merge branch 'main' into zzc/dev/readme_link
a1012112796 Oct 19, 2022
a98877d
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 20, 2022
578f24f
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 21, 2022
6eeed55
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 21, 2022
5df8489
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 21, 2022
27348eb
Merge branch 'main' into zzc/dev/readme_link
a1012112796 Oct 22, 2022
a194de5
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 22, 2022
bfff503
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 22, 2022
b2e3293
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 22, 2022
b26d945
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 23, 2022
db34de1
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 23, 2022
f59d31f
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 23, 2022
08350f4
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 23, 2022
487af90
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 24, 2022
d5c4780
Merge branch 'main' into zzc/dev/readme_link
lunny Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
Copy link
Contributor

@wxiaoguang wxiaoguang Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function was designed for work for both languageCode=en-US and languageCode=en.

This change only supports languageCode=en-US, while line 158-159 are for languageCode=en, the behaviors are inconsistent now.

However, I have no objection to merge this PR since there is no languageCode=en in Gitea code, while it's better to document the behavior.

Copy link
Member Author

@a1012112796 a1012112796 Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, In my view, the en is same with en-US (or other). in other words, it's not a good idea to add a new file named as locale_en.ini in i18n folder. and the link 'https://gitea.com/?lang=en' should have same behave with 'https://gitea.com/?lang=en-US'

and if just choose language while ui, languageCode=en willn't occure.

Copy link
Contributor

@wxiaoguang wxiaoguang Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, Gitea doesn't use the en or zh at the the moment, the code is just there. Line 158-159 won't run in current Gitea, it's just inconsistent dead code. (just a hint)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, In my view, the en is same with en-US (or other).

There is a complex and special relationship between en, en-US, en_001 and other en subvariants e.g. en_GB

Whilst en-US is the default locale for en, it is not en. For example the rules for dates in en-US are extremely different from those for almost every other en variant. CLDR has en_001 which almost completely overrides most US weirdness and means that most English regional locales inherit from en_001 rather than en directly.

https://cldr.unicode.org/development/development-process/design-proposals/english-inheritance

Our translation scheme isn't really designed at present to properly consider regional localisation but we're probably going to have to consider it at some point soon.

}

// 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