diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-01-02 11:33:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-02 04:33:57 +0100 |
commit | e61b390d545919244141b699b28e3fbc42adc66f (patch) | |
tree | de17418a260234e1043a6d3a130c2b4a8c27640a /modules/templates | |
parent | 88da7a7174f9c1568cc2d8d084d6b05a8d268690 (diff) | |
download | gitea-e61b390d545919244141b699b28e3fbc42adc66f.tar.gz gitea-e61b390d545919244141b699b28e3fbc42adc66f.zip |
Unify and simplify TrN for i18n (#18141)
Refer: https://github.com/go-gitea/gitea/pull/18135#issuecomment-1003246099
Now we have a unique and simple `TrN`, and make the fix of PR #18135 also use the better `TrN` logic.
Diffstat (limited to 'modules/templates')
-rw-r--r-- | modules/templates/helper.go | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go index a05c0c1a95..fc07b49c71 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -239,7 +239,6 @@ func NewFuncMap() []template.FuncMap { "DisableImportLocal": func() bool { return !setting.ImportLocalPaths }, - "TrN": TrN, "Dict": func(values ...interface{}) (map[string]interface{}, error) { if len(values)%2 != 0 { return nil, errors.New("invalid dict call") @@ -857,69 +856,6 @@ func DiffLineTypeToStr(diffType int) string { return "same" } -// Language specific rules for translating plural texts -var trNLangRules = map[string]func(int64) int{ - "en-US": func(cnt int64) int { - if cnt == 1 { - return 0 - } - return 1 - }, - "lv-LV": func(cnt int64) int { - if cnt%10 == 1 && cnt%100 != 11 { - return 0 - } - return 1 - }, - "ru-RU": func(cnt int64) int { - if cnt%10 == 1 && cnt%100 != 11 { - return 0 - } - return 1 - }, - "zh-CN": func(cnt int64) int { - return 0 - }, - "zh-HK": func(cnt int64) int { - return 0 - }, - "zh-TW": func(cnt int64) int { - return 0 - }, - "fr-FR": func(cnt int64) int { - if cnt > -2 && cnt < 2 { - return 0 - } - return 1 - }, -} - -// TrN returns key to be used for plural text translation -func TrN(lang string, cnt interface{}, key1, keyN string) string { - var c int64 - if t, ok := cnt.(int); ok { - c = int64(t) - } else if t, ok := cnt.(int16); ok { - c = int64(t) - } else if t, ok := cnt.(int32); ok { - c = int64(t) - } else if t, ok := cnt.(int64); ok { - c = t - } else { - return keyN - } - - ruleFunc, ok := trNLangRules[lang] - if !ok { - ruleFunc = trNLangRules["en-US"] - } - - if ruleFunc(c) == 0 { - return key1 - } - return keyN -} - // MigrationIcon returns a SVG name matching the service an issue/comment was migrated from func MigrationIcon(hostname string) string { switch hostname { |