Albirew/nyaa-pantsu
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

52 lignes
1.1 KiB
Go

package torrentLanguages
import (
"strings"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
)
var torrentLanguages []string
func initTorrentLanguages() {
languages := publicSettings.GetAvailableLanguages()
for code := range languages {
torrentLanguages = append(torrentLanguages, code)
}
// Also support languages we don't have a translation
torrentLanguages = append(torrentLanguages, config.Conf.Torrents.AdditionalLanguages...)
}
// 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 ""
}