Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Changing to the new behaviour of package languages

Cette révision appartient à :
akuma06 2017-07-11 22:25:52 +02:00 révisé par ewhal
Parent c564301e35
révision e1d6e7df20
11 fichiers modifiés avec 31 ajouts et 30 suppressions

Voir le fichier

@ -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 {

Voir le fichier

@ -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;
}

Voir le fichier

@ -22,8 +22,8 @@
<div name="language" class="form-input language">
{{ range _, language := GetTorrentLanguages() }}
<span class="input-group">
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}"{{if contains(Form.Languages, language) }} checked{{end}}>
<label for="lang-{{ language }}" class="flag flag-{{ FlagCode(language) }}" title="{{LanguageName(language, T)}}"></label>
<input type="checkbox" name="languages" id="lang-{{ language.Code }}" value="{{language.Code}}"{{if contains(Form.Languages, language) }} checked{{end}}>
<label for="lang-{{ language.Code }}" class="flag flag-{{ language.Flag() }}" title="{{LanguageName(language, T)}}"></label>
</span>
{{ end }}
</div>

Voir le fichier

@ -58,7 +58,7 @@
{{ range _, language := GetTorrentLanguages() }}
<span class="input-group">
<input type="checkbox" name="lang" id="lang-{{ language }}" value="{{language}}"{{ range _, v := Search.Languages}}{{ if v.Code == language }} checked{{end}}{{end}}>
<label for="lang-{{ language }}" class="flag flag-{{ FlagCode(language) }}" title="{{LanguageName(language, T)}}"></label>
<label for="lang-{{ language.Code }}" class="flag flag-{{ language.Flag() }}" title="{{LanguageName(language, T)}}"></label>
</span>
{{ end }}
</div>

Voir le fichier

@ -27,8 +27,8 @@
<div name="language" class="form-input language">
{{ range _, language := GetTorrentLanguages() }}
<span class="input-group">
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}"{{if contains(Form.Languages, language) }} checked{{end}}>
<label for="lang-{{ language }}" class="flag flag-{{ language }}" title="{{LanguageName(language, T)}}"></label>
<input type="checkbox" name="languages" id="lang-{{ language.Code }}" value="{{language.Code}}"{{if contains(Form.Languages, language.Code) }} checked{{end}}>
<label for="lang-{{ language.Code }}" class="flag flag-{{ language.Flag() }}" title="{{LanguageName(language, T)}}"></label>
</span>
{{ end }}
</div>

Voir le fichier

@ -49,7 +49,7 @@
<a href="{{ URL.Parse("/search?c="+.Category+"_"+ .SubCategory) }}" title="{{ T(CategoryName(.Category, .SubCategory)) }}" class="category">
{{if .Languages[0] != "" }}
<a href="{{ URL.Parse("/search?c="+.Category+"_"+ .SubCategory +"&lang=") }}{{ range key, language := .Languages }}{{ language }}{{ if len(.Languages) > 1 && (key+1) < len(.Languages) }},{{ end }}{{ end }}">
<img src="/img/blank.gif" alt="{{ LanguageName(.Languages[0], T) }}" class="flag flag-{{ (len(.Languages) == 1) ? .Languages[0] : "multiple" }}" title=" {{ range key, language := .Languages }}{{ LanguageName(language, T) }}{{ if len(.Languages) > 1 && (key+1) < len(.Languages) }},{{ end }}{{ end }}">
<img src="/img/blank.gif" alt="{{ LanguageName(.Languages[0], T) }}" class="flag flag-{{ (len(.Languages) == 1) ? .Languages[0].Flag() : "multiple" }}" title=" {{ range key, language := .Languages }}{{ LanguageName(language, T) }}{{ if len(.Languages) > 1 && (key+1) < len(.Languages) }},{{ end }}{{ end }}">
</a>
{{end}}
</a>
@ -241,7 +241,7 @@
"<div class=\"nyaa-cat nyaa-cat-"+ torrent.sub_category +"\">"+
{{end}}
"<a href=\"{{URL.Parse("/search?c=") }}"+ torrent.category + "_" + torrent.sub_category +"\" title=\""+ T.r(torrent.category+"_"+torrent.sub_category)+"\">"+
((torrent.languages[0] != "") ? "<a href=\"{{URL.Parse("/search?c=") }}"+ torrent.category + "_" + torrent.sub_category +"&lang=" + torrent.languages.join(",") +"\"><img src=\"img/blank.gif\" class=\"flag flag-"+ ((torrent.languages.length == 1) ? torrent.languages[0] : "multiple") +"\" title=\""+torrent.languages.map(function (el, i) { return T.r(el)}).join(",")+"\"></a>" : "") +
((torrent.languages[0] != "") ? "<a href=\"{{URL.Parse("/search?c=") }}"+ torrent.category + "_" + torrent.sub_category +"&lang=" + torrent.languages.join(",") +"\"><img src=\"img/blank.gif\" class=\"flag flag-"+ ((torrent.languages.length == 1) ? flagCode(torrent.languages[0]) : "multiple") +"\" title=\""+torrent.languages.map(function (el, i) { return T.r(el)}).join(",")+"\"></a>" : "") +
"</a>"+
"</div></td>"+
"<td class=\"tr-name home-td\"><a href=\"/view/"+torrent.id+"\">"+Templates.EncodeEntities(torrent.name) +"</a></td>"+

Voir le fichier

@ -33,8 +33,8 @@
<div name="language" class="form-input language">
{{ range _, language := GetTorrentLanguages() }}
<span class="input-group">
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}">
<label for="lang-{{ language }}" class="flag flag-{{ language }}" title="{{LanguageName(language, T)}}"></label>
<input type="checkbox" name="languages" id="lang-{{ language.Code }}" value="{{language.Code}}">
<label for="lang-{{ language.Code }}" class="flag flag-{{ language.Flag() }}" title="{{LanguageName(language, T)}}"></label>
</span>
{{ end }}
</div>

Voir le fichier

@ -36,7 +36,7 @@
<td class="tr-flag torrent-view-td torrent-info-data">
{{ range _, language := Torrent.Languages}}
{{ if language != "" }}
<span><img src="/img/blank.gif" alt="{{ LanguageName(language, T) }}" class="flag flag-{{ language }}" title="{{ LanguageName(language, T) }}"></img> {{ LanguageName(language, T) }}</span>
<span><img src="/img/blank.gif" alt="{{ LanguageName(language, T) }}" class="flag flag-{{ language.Flag() }}" title="{{ LanguageName(language, T) }}"></img> {{ LanguageName(language, T) }}</span>
{{end}}
{{end}}
</td>

Voir le fichier

@ -26,7 +26,7 @@
<a href="{{URL.Parse ("/search?c="+ torrent.Category + "_" +torrent.SubCategory) }}" title="{{T(CategoryName(torrent.Category, torrent.SubCategory))}}" class="category">
{{ if torrent.Languages[0] != "" }}
<a href="{{ URL.Parse("/search?c="+torrent.Category+"_"+ torrent.SubCategory +"&lang=") }}{{ range key, language := torrent.Languages }}{{ language }}{{ if len(torrent.Languages) > 1 && (key+1) < len(torrent.Languages) }},{{ end }}{{ end }}">
<img src="/img/blank.gif" alt="{{ LanguageName(torrent.Languages[0], T) }}" class="flag flag-{{ (len(torrent.Languages) == 1) ? FlagCode(torrent.Languages[0]) : "multiple" }}" title=" {{ range key, language := torrent.Languages }}{{ LanguageName(language, T) }}{{ if len(torrent.Languages) > 1 && (key+1) < len(torrent.Languages) }},{{ end }}{{ end }}">
<img src="/img/blank.gif" alt="{{ LanguageName(torrent.Languages[0], T) }}" class="flag flag-{{ (len(torrent.Languages) == 1) ? torrent.Languages[0].Flag() : "multiple" }}" title=" {{ range key, language := torrent.Languages }}{{ LanguageName(language, T) }}{{ if len(torrent.Languages) > 1 && (key+1) < len(torrent.Languages) }},{{ end }}{{ end }}">
</a>
{{end}}
</a>

Voir le fichier

@ -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

Voir le fichier

@ -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