From 20ba05f8b5fa3f1e7f6a08c24824b1a69126b7b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20BE=C4=9EEN?= Date: Wed, 29 Jul 2020 01:56:03 +0300 Subject: [PATCH] Reads languages from store folder (#139) * Reads languages from store folder * Delete unnecessary print statement --- internal/api/system.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/api/system.go b/internal/api/system.go index 24a0645..b493222 100644 --- a/internal/api/system.go +++ b/internal/api/system.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "github.com/gorilla/mux" "github.com/passwall/passwall-server/internal/app" @@ -56,9 +57,22 @@ func Languages(s storage.Store) http.HandlerFunc { Item []string `json:"languages"` } - // TODO: Read store folder and parse of localization files for this slice + files, err := ioutil.ReadDir("./store") + if err != nil { + RespondWithError(w, http.StatusInternalServerError, err.Error()) + } + + s := []string{} + for _, f := range files { + // Since Split function returns string slice first split filename from extension + e := strings.Split(f.Name(), ".") + // Than split from the language part eg localization-xx + l := strings.Split(e[0], "-") + s = append(s, l[1]) + } + langs := Languages{ - Item: []string{"tr", "en"}, + Item: s, } RespondWithJSON(w, http.StatusOK, langs.Item)