File tree Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Expand file tree Collapse file tree 4 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ struct TrData {
22
22
// m['en']['house'] == 'House'
23
23
fn load_tr_map () map [string ]map [string ]string {
24
24
// 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' )
26
26
mut res := map [string ]map [string ]string {}
27
27
for tr_path in files {
28
28
lang := fetch_lang_from_tr_path (tr_path)
@@ -35,7 +35,7 @@ fn load_tr_map() map[string]map[string]string {
35
35
// println('val="${val}"')
36
36
nl_pos := s.index ('\n ' ) or { continue }
37
37
key := s[..nl_pos]
38
- val := s[nl_pos..]
38
+ val := s[nl_pos + 1 ..]
39
39
// v := vals[i + 1]
40
40
// println('key="${key}" => val="${v}"')
41
41
res[lang][key] = val
@@ -46,7 +46,7 @@ fn load_tr_map() map[string]map[string]string {
46
46
}
47
47
48
48
fn fetch_lang_from_tr_path (path string ) string {
49
- return path.find_between ('/' , '.' )
49
+ return path.find_between (os.path_separator , '.' )
50
50
}
51
51
52
52
// Used by %key in templates
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ msg_hello
2
+ Hello
Original file line number Diff line number Diff line change
1
+ msg_hello
2
+ Olá
You can’t perform that action at this time.
0 commit comments