Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Merge branch 'master' of github.com:ewhal/nyaa

Cette révision appartient à :
ayame-git 2017-05-10 23:06:22 +03:00
révision cf601d1e52
9 fichiers modifiés avec 146 ajouts et 95 suppressions

Voir le fichier

@ -123,3 +123,10 @@ a:hover {
#mainmenu a.nightswitch {
background-image: url(/img/moon.png);
}
/* Force images on description to fit width */
#description img {
display: block;
max-width: 100%;
height: auto;
}

Voir le fichier

@ -104,7 +104,8 @@ td {
.comment-row td:first-of-type {
vertical-align: top;
text-align: right;
text-align: left;
color:#bbb;
}
/* Table style & fixes */
@ -339,3 +340,10 @@ footer {
color: #616161;
text-shadow: -1px -1px #999999;
}
/* Force images on description to fit width */
#description img {
display: block;
max-width: 100%;
height: auto;
}

Voir le fichier

@ -70,4 +70,7 @@ var FuncMap = template.FuncMap{
"HasAdmin": userPermission.HasAdmin,
"GetRole": userPermission.GetRole,
"IsFollower": userPermission.IsFollower,
"NoEncode": func(str string) template.HTML {
return template.HTML(str)
},
}

Voir le fichier

@ -59,6 +59,7 @@ type UserProfileEditVariables struct {
UserForm userForms.UserForm
FormErrors map[string][]string
FormInfos map[string][]string
Languages map[string]string
Search SearchForm
Navigation Navigation
User *model.User

Voir le fichier

@ -115,7 +115,8 @@ func UserDetailsHandler(w http.ResponseWriter, r *http.Request) {
languages.SetTranslationFromRequest(viewProfileEditTemplate, r, "en-us")
searchForm := NewSearchForm()
searchForm.HideAdvancedSearch = true
htv := UserProfileEditVariables{&userProfile, b, form.NewErrors(), form.NewInfos(), searchForm, Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)}
availableLanguages := languages.GetAvailableLanguages()
htv := UserProfileEditVariables{&userProfile, b, form.NewErrors(), form.NewInfos(), availableLanguages, searchForm, Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)}
err := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
@ -158,7 +159,8 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
}
}
}
htv := UserProfileEditVariables{&userProfile, b, err, infos, NewSearchForm(), Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)}
availableLanguages := languages.GetAvailableLanguages()
htv := UserProfileEditVariables{&userProfile, b, err, infos, availableLanguages, NewSearchForm(), Navigation{}, currentUser, r.URL, mux.CurrentRoute(r)}
errorTmpl := viewProfileEditTemplate.ExecuteTemplate(w, "index.html", htv)
if errorTmpl != nil {
http.Error(w, errorTmpl.Error(), http.StatusInternalServerError)

Voir le fichier

@ -23,7 +23,10 @@
<div class="col-lg-8">
<div class="ui-select">
<select id="language" name="language" class="form-control">
<option value="en-us" {{ if eq .Language "en-us" }}selected{{end}}>{{T "english"}} ({{ T "default" }})</option>
{{ $userLanguage := .Language }}
{{ range $tag, $translatedName := $.Languages }}
<option value="{{ $tag }}" {{ if or (eq $userLanguage $tag) (and (eq $userLanguage "") (eq $tag "en-us")) }}selected{{end}}>{{ $translatedName }} {{if eq $tag "en-us"}}({{ T "default" }}){{end}}</option>
{{ end }}
</select>
</div>
{{ range (index $.FormErrors "language")}}

Voir le fichier

@ -1,96 +1,100 @@
{{define "title"}}{{.Torrent.Name}}{{end}}
{{define "contclass"}}cont-view{{end}}
{{define "content"}}
<div class="blockBody">
{{with .Torrent}}
<hr>
<table class="table table-borderless">
<tr {{if eq .Status 2}}class="remake"{{end}}
{{if eq .Status 3}}class="trusted"{{end}}
{{if eq .Status 4}}class="aplus"{{end}}>
<td>{{T "name"}}</td>
<td>
{{.Name}}
<img style="float:right" src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}">
</td>
</tr>
<tr>
<td>{{T "hash"}}</td>
<td class="torrent-hash">{{.Hash}}</td>
</tr>
<tr>
<td>{{T "date"}}</td>
<td class="date-full">{{.Date}}</td>
</tr>
<tr>
<td>{{T "size"}}</td>
<td>{{.Filesize}}</td>
</tr>
<tr>
<td>Uploader</td>
<td>
<a href="{{$.URL.Parse (printf "/user/%d/-" .UploaderID) }}">{{.UploaderName}}</a>
{{if ne .OldUploader ""}}
({{.OldUploader}})
<div class="blockBody">
{{with .Torrent}}
<hr>
<div class="content" style="margin-bottom: 2em;">
<div class="row">
<div class="col-md-8">
<div class="row">
<div class="col-md-12">
<h3 style="word-break:break-all" {{if eq .Status 2}}class="remake" {{end}} {{if eq .Status 3}}class="trusted" {{end}} {{if eq .Status 4}}class="aplus"{{end}}>{{.Name}}</h3>
<div class="uploaded_by">
<img style="float:left; margin-right: 1em;" src="{{$.URL.Parse (printf "/img/torrents/%s.png" .SubCategory) }}">
<h4>Uploaded by <a href="{{$.URL.Parse (printf "/user/%d/-" .UploaderID) }}">{{.UploaderName}}</a></h4>
</div>
</div>
</div>
<br />
<div class="row">
<div class="col-md-12">
<a style="margin: 5px;" aria-label="Magnet Button" href="{{.Magnet}}" type="button" class="btn btn-lg btn-success download-btn">
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download!
</a>
{{if ne .TorrentLink ""}}
<a style="margin: 5px;" aria-label="Torrent file" href="{{.TorrentLink}}" type="button" class="btn btn-lg btn-success download-btn">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Torrent file
</a>
<a style="margin: 5px;" aria-label="Report button" href="{{.TorrentLink}}" type="button" data-toggle="modal" data-target="#reportModal" class="btn btn-danger btn-lg download-btn">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Report!
</a> {{end}}
{{ if HasAdmin $.User}}
<a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="btn btn-danger btn-lg" onclick="if (!confirm('Are you sure?')) return false;"><i class="glyphicon glyphicon-trash"></i>{{ T "delete" }}</a>
{{end}}
</td>
{{if ne .WebsiteLink ""}}
<tr>
<td>{{T "Link"}}</td>
<td><a href="{{.WebsiteLink}}">{{.WebsiteLink}}</td>
</tr>
{{end}}
<tr>
<td>{{T "links"}}</td>
<td>
<a aria-label="Magnet Button" href="{{.Magnet}}" type="button" class="btn btn-success download-btn">
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download!
</a>
<a style="padding-left: 0.5em"></a>
<a aria-label="Torrent file" href="{{.TorrentLink}}" type="button" class="btn btn-success download-btn">
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Torrent file
</a>
<a aria-label="Report button" href="{{.TorrentLink}}" type="button" data-toggle="modal" data-target="#reportModal" class="btn btn-danger download-btn">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Report!
</a>
</td>
</tr>
<tr>
<td>{{T "description"}}</td>
<td>{{.Description}}</td>
</tr>
<tr style="height:2em">
<td></td>
<td></td>
</tr>
<tr>
<td>{{T "comments"}}</td>
<td></td>
</tr>
{{ range $index, $element := .Comments }}
<tr class="comment-row" id="comment_{{$index}}">
<td>
<a href="#comment_{{$index}}">{{$index}}</a> {{.Username}}
</td>
<td>{{.Content}}</td>
</tr>
{{end}}
</table>
{{end}}
<form method="post">
<div class="form-group">
{{/* There should be a better way to use translation on this... */}}
<label for="comment">{{ if gt .User.ID 0}} {{T "submit_a_comment_as_username" .User.Username}} {{else}} {{T "submit_a_comment_as_anonymous"}} {{end}}</label>
<textarea name="comment" class="form-control" rows="5"></textarea>
</div>
</div>
</div>
<div class="col-md-4">
<h4>{{T "hash"}}</h4>
<p>{{.Hash}}</p>
<hr>
<h4>{{T "date"}}</h4>
<p>{{.Date}}</p>
<hr>
<h4>{{T "size"}}</h4>
<p>{{.Filesize}}</p>
<hr>
{{if ne .WebsiteLink ""}}
<h4>{{T "Link"}}</h4>
<p><a href="{{.WebsiteLink}}">{{.WebsiteLink}}</a></p>
<hr>
{{end}}
</div>
</div>
{{with .Captcha}} {{block "captcha" .}}{{end}} {{end}}
<input type="submit" value="{{T " submit "}}">
</form>
<div class="row" id="description">
<div class="col-md-12">
<h4>{{T "description"}}</h4>
<div style="word-break:break-all;">{{.Description}}</div>
</div>
</div>
<div class="row" id="comments">
<div class="col-md-12">
<h4>{{T "comments"}}</h4>
{{ range $index, $element := .Comments }}
<div class="row comment-row" id="comment_{{$index}}">
<div class="col-md-4">
<a href="#comment_{{$index}}">{{$index}}</a> {{.Username}}
</div>
<div class="col-md-8">
{{.Content}}
</div>
</div>
{{end}}
</div>
</div>
</div>
{{end}}
<div class="row" style="margin-bottom: 2em;">
<div class="col-md-12">
<form method="post">
<div class="form-group">
{{/* There should be a better way to use translation on this... */}}
<label for="comment">{{ if gt .User.ID 0}} {{T "submit_a_comment_as_username" .User.Username}} {{else}} {{T "submit_a_comment_as_anonymous"}} {{end}}</label>
<textarea name="comment" class="form-control" rows="5"></textarea>
</div>
{{with .Captcha}} {{block "captcha" .}}{{end}} {{end}}
<input type="submit" value="{{T " submit "}}">
</form>
</div>
</div>
</div>
{{with .Torrent}}
<div id="reportModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
@ -102,15 +106,14 @@
<form method="post" action="/report/{{.ID}}">
<input type="radio" name="report_type" value="illegal"> Illegal content <br/>
<input type="radio" name="report_type" value="spam"> Spam / garbage
{{end}}
{{with .Captcha}} {{block "captcha" .}}{{end}} {{end}}
<button type="submit" class="btn btn-default">Report!</button>
{{end}}
{{with .Captcha}} {{block "captcha" .}}{{end}} {{end}}
<button type="submit" class="btn btn-default">Report!</button>
</form> <br />
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
{{end}}

Voir le fichier

@ -25,7 +25,7 @@
},
{
"id":"signup_box_title",
"translation": "Iscriviti <small>È gratuito e lo sara per sempre.</small>"
"translation": "Iscriviti <small>È gratuito e lo sarà per sempre.</small>"
},
{
"id":"username",
@ -269,7 +269,7 @@
},
{
"id": "answer_is_nyaa_db_lost",
"translation": "Abbiamo un database dei torrent di nyaa fino al <s>5 Aprile/s> 1° Maggio. Questo vuol dire che quasi niente è andato perduto."
"translation": "Abbiamo un database dei torrent di nyaa fino al <s>5 Aprile</s> 1° Maggio. Questo vuol dire che quasi niente è andato perduto."
},
{
"id": "answer_is_sukebei_db_lost",

Voir le fichier

@ -3,6 +3,7 @@ package languages
import (
"fmt"
"github.com/nicksnyder/go-i18n/i18n"
"github.com/ewhal/nyaa/service/user"
"html/template"
"net/http"
)
@ -33,6 +34,22 @@ func TfuncWithFallback(language string, languages ...string) (i18n.TranslateFunc
}, nil
}
func GetAvailableLanguages() (languages map[string]string) {
languages = make(map[string]string)
var T i18n.TranslateFunc
for _, languageTag := range i18n.LanguageTags() {
T, _ = i18n.Tfunc(languageTag)
/* Translation files should have an ID with the translated language name.
If they don't, just use the languageTag */
if languageName := T("language_name"); languageName != "language_name" {
languages[languageTag] = languageName;
} else {
languages[languageTag] = languageTag
}
}
return
}
func SetTranslation(tmpl *template.Template, language string, languages ...string) i18n.TranslateFunc {
T, _ := TfuncWithFallback(language, languages...)
tmpl.Funcs(map[string]interface{}{
@ -44,12 +61,19 @@ func SetTranslation(tmpl *template.Template, language string, languages ...strin
}
func SetTranslationFromRequest(tmpl *template.Template, r *http.Request, defaultLanguage string) i18n.TranslateFunc {
userLanguage := ""
user, _, err := userService.RetrieveCurrentUser(r)
if err == nil {
userLanguage = user.Language;
}
cookie, err := r.Cookie("lang")
cookieLanguage := ""
if err == nil {
cookieLanguage = cookie.Value
}
// go-i18n supports the format of the Accept-Language header, thankfully.
headerLanguage := r.Header.Get("Accept-Language")
return SetTranslation(tmpl, cookieLanguage, headerLanguage, defaultLanguage)
return SetTranslation(tmpl, userLanguage, cookieLanguage, headerLanguage, defaultLanguage)
}