mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 13:07:36 +03:00
Cater for differences when loading embedded Assets and in dev mode
This commit is contained in:
parent
056d5e7111
commit
496b467c1d
1 changed files with 22 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
|
@ -81,6 +82,7 @@ func loadTranslations() (loadError error) {
|
|||
loadError = err
|
||||
return
|
||||
}
|
||||
var languages []string
|
||||
for _, f := range files {
|
||||
t, err := loadTranslation(f.Name())
|
||||
if err != nil {
|
||||
|
@ -88,26 +90,38 @@ func loadTranslations() (loadError error) {
|
|||
continue
|
||||
}
|
||||
translations[t.ID] = t
|
||||
languages = append(languages, t.ID)
|
||||
}
|
||||
log.Info("Loading translations", "languages", languages)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func loadTranslation(fileName string) (trans translation, err error) {
|
||||
id := strings.TrimSuffix(fileName, filepath.Ext(fileName))
|
||||
filePath := filepath.Join(i18nFolder, fileName)
|
||||
func loadTranslation(fileName string) (translation translation, err error) {
|
||||
// Get id and full path
|
||||
name := filepath.Base(fileName)
|
||||
id := strings.TrimSuffix(name, filepath.Ext(name))
|
||||
filePath := filepath.Join(i18nFolder, name)
|
||||
|
||||
// Load translation from json file
|
||||
data, err := resources.Asset(filePath)
|
||||
trans.Data = string(data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var out map[string]interface{}
|
||||
err = json.Unmarshal(data, &out)
|
||||
if err != nil {
|
||||
if err = json.Unmarshal(data, &out); err != nil {
|
||||
return
|
||||
}
|
||||
trans.Name = out["languageName"].(string)
|
||||
trans.ID = id
|
||||
|
||||
// Compress JSON
|
||||
buf := new(bytes.Buffer)
|
||||
if err = json.Compact(buf, data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
translation.Data = buf.String()
|
||||
translation.Name = out["languageName"].(string)
|
||||
translation.ID = id
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue