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 {
2222// m['en']['house'] == 'House'
2323fn 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
4848fn 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
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