summaryrefslogtreecommitdiffstats
path: root/modules/templates
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2017-10-15 02:17:39 +0300
committerGitHub <noreply@github.com>2017-10-15 02:17:39 +0300
commitf42dbdbae59600266d03357f9693c659adc9cab3 (patch)
tree90b42df32a5f064d9055fec37c909aa83c432dcc /modules/templates
parent8863e74f2aa7150605712eb21468b6f1305289f7 (diff)
downloadgitea-f42dbdbae59600266d03357f9693c659adc9cab3.tar.gz
gitea-f42dbdbae59600266d03357f9693c659adc9cab3.zip
Add Activity page to repository (#2674)
* Add Activity page to repository * Add request data for activity * Add issue data for activity * Add user unit right checks * Add releases to activity * Log repository unit loading error
Diffstat (limited to 'modules/templates')
-rw-r--r--modules/templates/helper.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index 0d307f4e9d..34881b788a 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -158,6 +158,7 @@ func NewFuncMap() []template.FuncMap {
"DisableGitHooks": func() bool {
return setting.DisableGitHooks
},
+ "TrN": TrN,
}}
}
@@ -342,3 +343,60 @@ 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
+ },
+}
+
+// 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
+}