-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
135 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"delete_resp_wrong_index": "Wrong index. Need enter command to format as <code>/delete 7</code>", | ||
"delete_unable_delete": "Unable to delete the secret", | ||
"delete_secrete_deleted": "The secret deleted", | ||
"query_no_secrets": "No secrets found", | ||
"setpass_unable_set": "Unable to set master password", | ||
"setpass_empty_pass": "Master password cannot be empty. Example of a valid command: <code>/setpass your_new_master_pass</code>", | ||
"setpasspass_setted": "Master password setted", | ||
"add_resp_command": "Please enter your description, login and password separated by newline:", | ||
"checkpass_please_enter_pass": "Please enter a master password:", | ||
"setpass_pass_changed": "Master password susccessful changed" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"delete_resp_wrong_index": "Неправильный индекс. Введите команду как в примере: <code>/delete 7</code>", | ||
"delete_unable_delete": "Не удалось удалить секрет", | ||
"delete_secrete_deleted": "Секрет удален", | ||
"query_no_secrets": "Секреты не найдены", | ||
"setpass_unable_set": "Не удалось установить мастер пароль", | ||
"setpass_empty_pass": "Мастер пароль не может быть пустым. Пример правильной комманды: <code>/setpass your_new_master_pass</code>", | ||
"setpasspass_setted": "Мастер пароль установлен", | ||
"add_resp_command": "Пожалуйста введите описание, пользователя и пароль, разделив их новой строкой:", | ||
"checkpass_please_enter_pass": "Пожалуйста введите мастер пароль:", | ||
"setpass_pass_changed": "Мастер пароль успешно изменен" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package localizator | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/fs" | ||
"path/filepath" | ||
"secretable/pkg/log" | ||
"strings" | ||
"sync" | ||
) | ||
|
||
type Localizator struct { | ||
locales []string | ||
m sync.Map | ||
} | ||
|
||
func (l *Localizator) InitFromFS(f fs.FS, basePath string) error { | ||
files, err := fs.ReadDir(f, basePath) | ||
if err != nil { | ||
return fmt.Errorf("read dir: %s", err.Error()) | ||
} | ||
|
||
for _, file := range files { | ||
if file.IsDir() { | ||
continue | ||
} | ||
|
||
target := filepath.Join(basePath, file.Name()) | ||
b, err := fs.ReadFile(f, target) | ||
if err != nil { | ||
log.Error("Read file " + target + " :" + err.Error()) | ||
continue | ||
} | ||
|
||
m := make(map[string]string) | ||
|
||
err = json.Unmarshal(b, &m) | ||
if err != nil { | ||
log.Error("Parse JSON " + target + " :" + err.Error()) | ||
continue | ||
} | ||
|
||
shortlocale := strings.TrimSuffix(file.Name(), ".json") | ||
|
||
l.locales = append(l.locales, shortlocale) | ||
for k, v := range m { | ||
l.m.Store(shortlocale+"."+k, v) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (l *Localizator) GetLocales() []string { | ||
a := make([]string, len(l.locales)) | ||
copy(a, l.locales) | ||
return a | ||
} | ||
|
||
func (l *Localizator) Get(locale string, key string) string { | ||
fmt.Println(locale + "." + key) | ||
v, ok := l.m.Load(locale + "." + key) | ||
if !ok { | ||
if locale != "en" { | ||
locale = "en" | ||
v, ok = l.m.Load(locale + "." + key) | ||
} | ||
if !ok { | ||
return "" | ||
} | ||
} | ||
|
||
return v.(string) | ||
} |