localization finish-up

pull/539/head
Alen BOHCELYAN 2017-02-13 22:56:31 +00:00 committed by Alen BOHCELYAN
parent 363ab116f4
commit 52e30dc0ae
12 changed files with 2168 additions and 23 deletions

View File

@ -3,7 +3,8 @@
"listen_url" : "0.0.0.0:3333",
"use_tls" : false,
"cert_path" : "gophish_admin.crt",
"key_path" : "gophish_admin.key"
"key_path" : "gophish_admin.key",
"languge": "tr-TR"
},
"phish_server" : {
"listen_url" : "0.0.0.0:80",
@ -13,5 +14,6 @@
},
"db_name" : "sqlite3",
"db_path" : "gophish.db",
"migrations_prefix" : "db/db_"
"migrations_prefix" : "db/db_",
"language": "tr"
}

View File

@ -12,6 +12,7 @@ type AdminServer struct {
UseTLS bool `json:"use_tls"`
CertPath string `json:"cert_path"`
KeyPath string `json:"key_path"`
Language string `json:"languge"`
}
// PhishServer represents the Phish server configuration details

View File

@ -435,7 +435,7 @@ func API_Pages_Id(w http.ResponseWriter, r *http.Request) {
p.UserId = ctx.Get(r, "user_id").(int64)
err = models.PutPage(&p)
if err != nil {
JSONResponse(w, models.Response{Success: false, Message: util.T("Error updating page: " + err.Error())}, http.StatusInternalServerError)
JSONResponse(w, models.Response{Success: false, Message: util.T("Error updating page:") + " " + err.Error()}, http.StatusInternalServerError)
return
}
JSONResponse(w, p, http.StatusOK)

View File

@ -429,7 +429,7 @@ func Settings(w http.ResponseWriter, r *http.Request) {
getTemplate(w, "settings").ExecuteTemplate(w, "base", params)
case r.Method == "POST":
err := auth.ChangePassword(r)
msg := models.Response{Success: true, Message: "Settings Updated Successfully"}
msg := models.Response{Success: true, Message: util.T("Settings Updated Successfully")}
if err == auth.ErrInvalidPassword {
msg.Message = "Invalid Password"
msg.Success = false
@ -480,7 +480,7 @@ func Login(w http.ResponseWriter, r *http.Request) {
session.Save(r, w)
http.Redirect(w, r, "/", 302)
} else {
Flash(w, r, "danger", "Invalid Username/Password")
Flash(w, r, "danger", util.T("Invalid Username/Password"))
http.Redirect(w, r, "/login", 302)
}
}
@ -492,14 +492,14 @@ func Logout(w http.ResponseWriter, r *http.Request) {
// Now that we are all registered, we can log the user in
session := ctx.Get(r, "session").(*sessions.Session)
delete(session.Values, "id")
Flash(w, r, "success", "You have successfully logged out")
Flash(w, r, "success", util.T("You have successfully logged out"))
http.Redirect(w, r, "/login", 302)
}
// Preview allows for the viewing of page html in a separate browser window
func Preview(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Method not allowed", http.StatusBadRequest)
http.Error(w, util.T("Method not allowed"), http.StatusBadRequest)
return
}
fmt.Fprintf(w, "%s", r.FormValue("html"))
@ -509,13 +509,13 @@ func Preview(w http.ResponseWriter, r *http.Request) {
func Clone(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
if r.Method != "POST" {
http.Error(w, "Method not allowed", http.StatusBadRequest)
http.Error(w, util.T("Method not allowed"), http.StatusBadRequest)
return
}
if url, ok := vars["url"]; ok {
Logger.Println(url)
}
http.Error(w, "No URL given.", http.StatusBadRequest)
http.Error(w, util.T("No URL given."), http.StatusBadRequest)
}
func getTemplate(w http.ResponseWriter, tmpl string) *template.Template {

View File

@ -35,25 +35,26 @@ import (
"github.com/NYTimes/gziphandler"
"github.com/gophish/gophish/auth"
"github.com/gophish/gophish/config"
"./config"
"./controllers"
"github.com/gophish/gophish/models"
"./util"
"github.com/gorilla/handlers"
"github.com/nicksnyder/go-i18n/i18n"
// "github.com/nicksnyder/go-i18n/i18n"
)
var Logger = log.New(os.Stdout, " ", log.Ldate|log.Ltime|log.Lshortfile)
func main() {
// Setup the global variables and settings
i18n.MustLoadTranslationFile("translations/en-US.all.json")
err := models.Setup()
if err != nil {
fmt.Println(err)
}
wg := &sync.WaitGroup{}
wg.Add(1)
util.ChangeLang(config.Conf.AdminConf.Language)
// Start the web servers
go func() {
defer wg.Done()

View File

@ -10,6 +10,7 @@ import (
ctx "github.com/gophish/gophish/context"
"github.com/gophish/gophish/models"
"github.com/gorilla/csrf"
"../util"
)
var CSRFExemptPrefixes = []string{
@ -36,7 +37,7 @@ func GetContext(handler http.Handler) http.HandlerFunc {
// Parse the request form
err := r.ParseForm()
if err != nil {
http.Error(w, "Error parsing request", http.StatusInternalServerError)
http.Error(w, util.T("Error parsing request"), http.StatusInternalServerError)
}
// Set the context appropriately here.
// Set the session
@ -77,7 +78,7 @@ func RequireAPIKey(handler http.Handler) http.HandlerFunc {
} else {
u, err := models.GetUserByAPIKey(ak)
if err != nil {
JSONError(w, 400, "Invalid API Key")
JSONError(w, 400, util.T("Invalid API Key"))
return
}
r = ctx.Set(r, "user_id", u.Id)

View File

@ -135,7 +135,7 @@ $(document).ready(function() {
var $point = $(this)
value = $point.attr('ct:value') || 0
cidx = $point.attr('ct:meta')
$toolTip.html(campaigns[cidx].name + '<br>' + T("Successes:" + " " + value.toString() + "%").show();
$toolTip.html(campaigns[cidx].name + '<br>' + T("Successes:") + " " + value.toString() + "%").show();
});
$chart.on('mouseleave', '.ct-point', function() {

View File

@ -32,7 +32,7 @@
</div>
<div style="display:none;" id="campaignResults">
<div class="row">
<h1 class="page-header" id="page-title">{{T "Results for campaign.name"}}</h1>
<h1 class="page-header" id="page-title">{{T "Results for"}} campaign.name</h1>
</div>
<div class="row">
<a href="/campaigns" class="btn btn-default">

View File

@ -130,5 +130,5 @@
"Error fetching groups": "{{T "Error fetching groups"}}"
}
</script>
<script src="/js/dist/app/users.min.js"></script>
<script src="/js/src/app/users.js"></script>
{{end}}

1070
translations/en-us.all.json Normal file

File diff suppressed because it is too large Load Diff

1062
translations/tr-tr.all.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ import (
"net/mail"
"os"
"time"
"strings"
"github.com/gophish/gophish/models"
"github.com/jordan-wright/email"
@ -26,14 +27,21 @@ import (
// Logger is used to send logging messages to stdout.
var Logger = log.New(os.Stdout, " ", log.Ldate|log.Ltime|log.Lshortfile)
var B i18n.TranslateFunc
var Lang = "en-US"
func T(text string) string{
T, _ := i18n.Tfunc("en-US", "en-US")
result := T(text)
if result == text {
fmt.Println("NON-TRANSLATION %s", text)
}
return result
if B == nil {
i18n.MustLoadTranslationFile("translations/" + strings.ToLower(Lang) + ".all.json")
B, _ = i18n.Tfunc(Lang)
}
return B(text)
}
func ChangeLang(lang string) {
Lang = lang
B = nil
}
// ParseMail takes in an HTTP Request and returns an Email object