diff --git a/controllers/template_functions.go b/controllers/template_functions.go index dd6d87e9..74f57862 100644 --- a/controllers/template_functions.go +++ b/controllers/template_functions.go @@ -7,6 +7,8 @@ import ( "strconv" "time" + "strings" + "github.com/CloudyKit/jet" "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/models" @@ -190,23 +192,16 @@ func templateFunctions(vars jet.VarMap) jet.VarMap { return "" }) vars.Set("GetTorrentLanguages", torrentLanguages.GetTorrentLanguages) - vars.Set("LanguageName", func(code string, T publicSettings.TemplateTfunc) template.HTML { - if code == "other" || code == "multiple" { - return T("language_" + code + "_name") + vars.Set("LanguageName", func(lang publicSettings.Language, T publicSettings.TemplateTfunc) string { + if strings.Contains(lang.Name, ",") { + langs := strings.Split(lang.Name, ", ") + tags := strings.Split(lang.Tag, ", ") + for k := range langs { + langs[k] = publicSettings.Translate(tags[k], string(T("language_code"))) + } + return strings.Join(langs, ", ") } - - if !torrentLanguages.LanguageExists(code) { - return T("unknown") - } - - return T("language_" + code + "_name") - }) - vars.Set("FlagCode", func(languageCode string) string { - if languageCode == "other" || languageCode == "multiple" { - return languageCode - } - - return torrentLanguages.FlagFromLanguage(languageCode) + return lang.Translate(T("language_code")) }) vars.Set("fileSize", func(filesize int64, T publicSettings.TemplateTfunc) template.HTML { if filesize == 0 { diff --git a/public/js/torrents.js b/public/js/torrents.js index 02a43f2f..221bbf27 100644 --- a/public/js/torrents.js +++ b/public/js/torrents.js @@ -49,7 +49,7 @@ function humanFileSize(bytes, si) { function flagCode(language) { split = language.split("-"); if (split.length > 1) { - return split[1]; + return split[0]; } return language; } diff --git a/templates/admin/paneltorrentedit.jet.html b/templates/admin/paneltorrentedit.jet.html index e2e1f765..43a33ffc 100644 --- a/templates/admin/paneltorrentedit.jet.html +++ b/templates/admin/paneltorrentedit.jet.html @@ -22,8 +22,8 @@
{{ range _, language := GetTorrentLanguages() }} - - + + {{ end }}
diff --git a/templates/layouts/partials/helpers/search.jet.html b/templates/layouts/partials/helpers/search.jet.html index 6b551c16..2ced6b49 100644 --- a/templates/layouts/partials/helpers/search.jet.html +++ b/templates/layouts/partials/helpers/search.jet.html @@ -58,7 +58,7 @@ {{ range _, language := GetTorrentLanguages() }} - + {{ end }} diff --git a/templates/site/torrents/edit.jet.html b/templates/site/torrents/edit.jet.html index 358a0d1a..15e6a1bd 100644 --- a/templates/site/torrents/edit.jet.html +++ b/templates/site/torrents/edit.jet.html @@ -27,8 +27,8 @@
{{ range _, language := GetTorrentLanguages() }} - - + + {{ end }}
diff --git a/templates/site/torrents/listing.jet.html b/templates/site/torrents/listing.jet.html index 375d4658..8a83aa7e 100644 --- a/templates/site/torrents/listing.jet.html +++ b/templates/site/torrents/listing.jet.html @@ -49,7 +49,7 @@ {{if .Languages[0] != "" }} - {{ LanguageName(.Languages[0], T) }} + {{ LanguageName(.Languages[0], T) }} {{end}} @@ -241,7 +241,7 @@ "
"+ {{end}} ""+ - ((torrent.languages[0] != "") ? "" : "") + + ((torrent.languages[0] != "") ? "" : "") + ""+ "
"+ ""+Templates.EncodeEntities(torrent.name) +""+ diff --git a/templates/site/torrents/upload.jet.html b/templates/site/torrents/upload.jet.html index 85648353..fea82255 100644 --- a/templates/site/torrents/upload.jet.html +++ b/templates/site/torrents/upload.jet.html @@ -33,8 +33,8 @@
{{ range _, language := GetTorrentLanguages() }} - - + + {{ end }}
diff --git a/templates/site/torrents/view.jet.html b/templates/site/torrents/view.jet.html index 5a9a0b03..a98b5b72 100644 --- a/templates/site/torrents/view.jet.html +++ b/templates/site/torrents/view.jet.html @@ -36,7 +36,7 @@ {{ range _, language := Torrent.Languages}} {{ if language != "" }} - {{ LanguageName(language, T) }} {{ LanguageName(language, T) }} + {{ LanguageName(language, T) }} {{ LanguageName(language, T) }} {{end}} {{end}} diff --git a/templates/site/user/torrents.jet.html b/templates/site/user/torrents.jet.html index 8b78c034..fc7fee68 100644 --- a/templates/site/user/torrents.jet.html +++ b/templates/site/user/torrents.jet.html @@ -26,7 +26,7 @@ {{ if torrent.Languages[0] != "" }} - {{ LanguageName(torrent.Languages[0], T) }} + {{ LanguageName(torrent.Languages[0], T) }} {{end}} diff --git a/utils/publicSettings/publicSettings.go b/utils/publicSettings/publicSettings.go index 31fd3705..a04125ab 100644 --- a/utils/publicSettings/publicSettings.go +++ b/utils/publicSettings/publicSettings.go @@ -227,8 +227,13 @@ func (langs Languages) Exist(name string) bool { // Translate accepts a languageCode in string and translate the language to the language from the language code func (lang *Language) Translate(languageCode template.HTML) string { - langTranslate := display.Tags(getParentTag(string(languageCode))) - return langTranslate.Name(lang) + return Translate(lang.Tag, string(languageCode)) +} + +// Translate accepts a languageCode in string and translate the language to the language from the language code in to +func Translate(languageCode string, to string) string { + langTranslate := display.Tags(getParentTag(to)) + return langTranslate.Name(languageCode) } // Flag reads the language's country code and return the country's flag if national true or the international flag for the language diff --git a/utils/torrentLanguages/torrent_languages.go b/utils/torrentLanguages/torrent_languages.go index 48e4bcfc..96b2dae1 100644 --- a/utils/torrentLanguages/torrent_languages.go +++ b/utils/torrentLanguages/torrent_languages.go @@ -25,6 +25,7 @@ func initTorrentLanguages() { last := len(torrentLanguages) - 1 if last > 0 && !strings.Contains(torrentLanguages[last].Name, lang.Name) { torrentLanguages[last].Name += ", " + lang.Name + torrentLanguages[last].Tag += ", " + lang.Tag } } else { prevLang = lang.Code