Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/utils/torrentLanguages/torrent_languages.go
akuma06 713ab02450 Added configor as a new library (#1126)
* Added configor as a new library

Now config is a singleton. You only need to do config.Get() instead of doing config.Conf.

* Forgot godep save 🐤

* Fix accidental removal of }
2017-07-10 22:11:05 +10:00

56 lignes
1,1 Kio
Go

package torrentLanguages
import (
"strings"
"sort"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
)
var torrentLanguages []string
func initTorrentLanguages() {
languages := publicSettings.GetAvailableLanguages()
for _, lang := range languages {
torrentLanguages = append(torrentLanguages, lang.Code)
}
// Also support languages we don't have a translation
torrentLanguages = append(torrentLanguages, config.Get().Torrents.AdditionalLanguages...)
sort.Strings(torrentLanguages)
}
// GetTorrentLanguages returns a list of available torrent languages.
func GetTorrentLanguages() []string {
if torrentLanguages == nil {
initTorrentLanguages()
}
return torrentLanguages
}
// LanguageExists check if said language is available for torrents
func LanguageExists(lang string) bool {
langs := GetTorrentLanguages()
for _, code := range langs {
if code == lang {
return true
}
}
return false
}
// FlagFromLanguage reads the language's country code.
func FlagFromLanguage(lang string) string {
languageSplit := strings.Split(lang, "-")
if len(languageSplit) > 1 {
return languageSplit[1]
}
return ""
}