d8e17478f8
* Add flags for torrents Add a new field, .Language, to the Torrent model, and a new package, torrentLanguages, which maps languages to flags. Added also a flag icon pack from googlei18n/region-flags, with (mostly) public domain flags from Wikipedia. * Optimize flags * Use FlagSprites CSS instead of .png files * Only use flags for languages we support * Add test for CSS flags Ensure that we have all the flags for the languages we support. * Add AdditionalLanguages field to config This allows us to support additional languages for new uploaded torrents, even if we have no translation for it. * Minor CSS fix * Add "other" and "multiple" torrent languages Also removed the TorrentLanguage struct, as it wasn't much useful. * Fix test * Add colspan=2 to category when language is empty Also hide the language column if empty. * Add lang field to search. Hopefully it works with Elasticsearch as well, but I haven't tested (lol Java) * Add language field to ES index and settings * Add language column to JS template * Add keyword type to language ES field * Remove 'raw' from keyword * Set "simple" analyzer on language * Document .Language field on Torrent model
53 lignes
1,1 Kio
Go
53 lignes
1,1 Kio
Go
package torrentLanguages
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/NyaaPantsu/nyaa/config"
|
|
"github.com/NyaaPantsu/nyaa/util/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
|
|
for _, code := range config.Conf.Torrents.AdditionalLanguages {
|
|
torrentLanguages = append(torrentLanguages, code)
|
|
}
|
|
}
|
|
|
|
// 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 ""
|
|
}
|