Changing to the new behaviour of package languages
Cette révision appartient à :
Parent
c564301e35
révision
e1d6e7df20
11 fichiers modifiés avec 31 ajouts et 30 suppressions
|
@ -7,6 +7,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/CloudyKit/jet"
|
"github.com/CloudyKit/jet"
|
||||||
"github.com/NyaaPantsu/nyaa/config"
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
"github.com/NyaaPantsu/nyaa/models"
|
"github.com/NyaaPantsu/nyaa/models"
|
||||||
|
@ -190,23 +192,16 @@ func templateFunctions(vars jet.VarMap) jet.VarMap {
|
||||||
return ""
|
return ""
|
||||||
})
|
})
|
||||||
vars.Set("GetTorrentLanguages", torrentLanguages.GetTorrentLanguages)
|
vars.Set("GetTorrentLanguages", torrentLanguages.GetTorrentLanguages)
|
||||||
vars.Set("LanguageName", func(code string, T publicSettings.TemplateTfunc) template.HTML {
|
vars.Set("LanguageName", func(lang publicSettings.Language, T publicSettings.TemplateTfunc) string {
|
||||||
if code == "other" || code == "multiple" {
|
if strings.Contains(lang.Name, ",") {
|
||||||
return T("language_" + code + "_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, ", ")
|
||||||
}
|
}
|
||||||
|
return lang.Translate(T("language_code"))
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
vars.Set("fileSize", func(filesize int64, T publicSettings.TemplateTfunc) template.HTML {
|
vars.Set("fileSize", func(filesize int64, T publicSettings.TemplateTfunc) template.HTML {
|
||||||
if filesize == 0 {
|
if filesize == 0 {
|
||||||
|
|
|
@ -49,7 +49,7 @@ function humanFileSize(bytes, si) {
|
||||||
function flagCode(language) {
|
function flagCode(language) {
|
||||||
split = language.split("-");
|
split = language.split("-");
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
return split[1];
|
return split[0];
|
||||||
}
|
}
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
<div name="language" class="form-input language">
|
<div name="language" class="form-input language">
|
||||||
{{ range _, language := GetTorrentLanguages() }}
|
{{ range _, language := GetTorrentLanguages() }}
|
||||||
<span class="input-group">
|
<span class="input-group">
|
||||||
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}"{{if contains(Form.Languages, language) }} checked{{end}}>
|
<input type="checkbox" name="languages" id="lang-{{ language.Code }}" value="{{language.Code}}"{{if contains(Form.Languages, language) }} checked{{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>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
{{ range _, language := GetTorrentLanguages() }}
|
{{ range _, language := GetTorrentLanguages() }}
|
||||||
<span class="input-group">
|
<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}}>
|
<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>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
<div name="language" class="form-input language">
|
<div name="language" class="form-input language">
|
||||||
{{ range _, language := GetTorrentLanguages() }}
|
{{ range _, language := GetTorrentLanguages() }}
|
||||||
<span class="input-group">
|
<span class="input-group">
|
||||||
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}"{{if contains(Form.Languages, language) }} checked{{end}}>
|
<input type="checkbox" name="languages" id="lang-{{ language.Code }}" value="{{language.Code}}"{{if contains(Form.Languages, language.Code) }} checked{{end}}>
|
||||||
<label for="lang-{{ language }}" class="flag flag-{{ language }}" title="{{LanguageName(language, T)}}"></label>
|
<label for="lang-{{ language.Code }}" class="flag flag-{{ language.Flag() }}" title="{{LanguageName(language, T)}}"></label>
|
||||||
</span>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
<a href="{{ URL.Parse("/search?c="+.Category+"_"+ .SubCategory) }}" title="{{ T(CategoryName(.Category, .SubCategory)) }}" class="category">
|
<a href="{{ URL.Parse("/search?c="+.Category+"_"+ .SubCategory) }}" title="{{ T(CategoryName(.Category, .SubCategory)) }}" class="category">
|
||||||
{{if .Languages[0] != "" }}
|
{{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 }}">
|
<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>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</a>
|
</a>
|
||||||
|
@ -241,7 +241,7 @@
|
||||||
"<div class=\"nyaa-cat nyaa-cat-"+ torrent.sub_category +"\">"+
|
"<div class=\"nyaa-cat nyaa-cat-"+ torrent.sub_category +"\">"+
|
||||||
{{end}}
|
{{end}}
|
||||||
"<a href=\"{{URL.Parse("/search?c=") }}"+ torrent.category + "_" + torrent.sub_category +"\" title=\""+ T.r(torrent.category+"_"+torrent.sub_category)+"\">"+
|
"<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>"+
|
"</a>"+
|
||||||
"</div></td>"+
|
"</div></td>"+
|
||||||
"<td class=\"tr-name home-td\"><a href=\"/view/"+torrent.id+"\">"+Templates.EncodeEntities(torrent.name) +"</a></td>"+
|
"<td class=\"tr-name home-td\"><a href=\"/view/"+torrent.id+"\">"+Templates.EncodeEntities(torrent.name) +"</a></td>"+
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
<div name="language" class="form-input language">
|
<div name="language" class="form-input language">
|
||||||
{{ range _, language := GetTorrentLanguages() }}
|
{{ range _, language := GetTorrentLanguages() }}
|
||||||
<span class="input-group">
|
<span class="input-group">
|
||||||
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}">
|
<input type="checkbox" name="languages" id="lang-{{ language.Code }}" value="{{language.Code}}">
|
||||||
<label for="lang-{{ language }}" class="flag flag-{{ language }}" title="{{LanguageName(language, T)}}"></label>
|
<label for="lang-{{ language.Code }}" class="flag flag-{{ language.Flag() }}" title="{{LanguageName(language, T)}}"></label>
|
||||||
</span>
|
</span>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<td class="tr-flag torrent-view-td torrent-info-data">
|
<td class="tr-flag torrent-view-td torrent-info-data">
|
||||||
{{ range _, language := Torrent.Languages}}
|
{{ range _, language := Torrent.Languages}}
|
||||||
{{ if language != "" }}
|
{{ 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}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<a href="{{URL.Parse ("/search?c="+ torrent.Category + "_" +torrent.SubCategory) }}" title="{{T(CategoryName(torrent.Category, torrent.SubCategory))}}" class="category">
|
<a href="{{URL.Parse ("/search?c="+ torrent.Category + "_" +torrent.SubCategory) }}" title="{{T(CategoryName(torrent.Category, torrent.SubCategory))}}" class="category">
|
||||||
{{ if torrent.Languages[0] != "" }}
|
{{ 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 }}">
|
<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>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -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
|
// 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 {
|
func (lang *Language) Translate(languageCode template.HTML) string {
|
||||||
langTranslate := display.Tags(getParentTag(string(languageCode)))
|
return Translate(lang.Tag, string(languageCode))
|
||||||
return langTranslate.Name(lang)
|
}
|
||||||
|
|
||||||
|
// 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
|
// Flag reads the language's country code and return the country's flag if national true or the international flag for the language
|
||||||
|
|
|
@ -25,6 +25,7 @@ func initTorrentLanguages() {
|
||||||
last := len(torrentLanguages) - 1
|
last := len(torrentLanguages) - 1
|
||||||
if last > 0 && !strings.Contains(torrentLanguages[last].Name, lang.Name) {
|
if last > 0 && !strings.Contains(torrentLanguages[last].Name, lang.Name) {
|
||||||
torrentLanguages[last].Name += ", " + lang.Name
|
torrentLanguages[last].Name += ", " + lang.Name
|
||||||
|
torrentLanguages[last].Tag += ", " + lang.Tag
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
prevLang = lang.Code
|
prevLang = lang.Code
|
||||||
|
|
Référencer dans un nouveau ticket