Skip to content

Commit 939d243

Browse files
authored
veb: fix key value and translation file name (#23203)
1 parent 05cbbfb commit 939d243

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

vlib/veb/tr.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct TrData {
2222
// m['en']['house'] == 'House'
2323
fn load_tr_map() map[string]map[string]string {
2424
// Find all translation files to figure out how many languages we have and to load the translation map
25-
files := os.walk_ext('translations/', '.tr')
25+
files := os.walk_ext('translations', '.tr')
2626
mut res := map[string]map[string]string{}
2727
for tr_path in files {
2828
lang := fetch_lang_from_tr_path(tr_path)
@@ -35,7 +35,7 @@ fn load_tr_map() map[string]map[string]string {
3535
// println('val="${val}"')
3636
nl_pos := s.index('\n') or { continue }
3737
key := s[..nl_pos]
38-
val := s[nl_pos..]
38+
val := s[nl_pos + 1..]
3939
// v := vals[i + 1]
4040
// println('key="${key}" => val="${v}"')
4141
res[lang][key] = val
@@ -46,7 +46,7 @@ fn load_tr_map() map[string]map[string]string {
4646
}
4747

4848
fn fetch_lang_from_tr_path(path string) string {
49-
return path.find_between('/', '.')
49+
return path.find_between(os.path_separator, '.')
5050
}
5151

5252
// Used by %key in templates

vlib/veb/tr_test.v

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module veb
2+
3+
import os
4+
5+
fn test_load_files_translations() {
6+
os.chdir(os.dir(@FILE))!
7+
8+
translations := load_tr_map()
9+
10+
assert 'pt-br' in translations
11+
assert 'en' in translations
12+
13+
assert 'msg_hello' in translations['pt-br']
14+
assert 'msg_hello' in translations['en']
15+
16+
assert translations['pt-br']['msg_hello'] == 'Olá'
17+
assert translations['en']['msg_hello'] == 'Hello'
18+
}

vlib/veb/translations/en.tr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
msg_hello
2+
Hello

vlib/veb/translations/pt-br.tr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
msg_hello
2+
Olá

0 commit comments

Comments
 (0)