Skip to content

Commit

Permalink
Reads languages from store folder (#139)
Browse files Browse the repository at this point in the history
* Reads languages from store folder

* Delete unnecessary print statement
  • Loading branch information
furkanbegen authored Jul 28, 2020
1 parent 77c277f commit 20ba05f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/api/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"

"github.com/gorilla/mux"
"github.com/passwall/passwall-server/internal/app"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 20ba05f

Please sign in to comment.