diff --git a/vlib/veb/tr.v b/vlib/veb/tr.v index b360652216..d7b4b2325e 100644 --- a/vlib/veb/tr.v +++ b/vlib/veb/tr.v @@ -22,7 +22,7 @@ struct TrData { // m['en']['house'] == 'House' fn load_tr_map() map[string]map[string]string { // Find all translation files to figure out how many languages we have and to load the translation map - files := os.walk_ext('translations/', '.tr') + files := os.walk_ext('translations', '.tr') mut res := map[string]map[string]string{} for tr_path in files { lang := fetch_lang_from_tr_path(tr_path) @@ -35,7 +35,7 @@ fn load_tr_map() map[string]map[string]string { // println('val="${val}"') nl_pos := s.index('\n') or { continue } key := s[..nl_pos] - val := s[nl_pos..] + val := s[nl_pos + 1..] // v := vals[i + 1] // println('key="${key}" => val="${v}"') res[lang][key] = val @@ -46,7 +46,7 @@ fn load_tr_map() map[string]map[string]string { } fn fetch_lang_from_tr_path(path string) string { - return path.find_between('/', '.') + return path.find_between(os.path_separator, '.') } // Used by %key in templates diff --git a/vlib/veb/tr_test.v b/vlib/veb/tr_test.v new file mode 100644 index 0000000000..bf92358bf6 --- /dev/null +++ b/vlib/veb/tr_test.v @@ -0,0 +1,18 @@ +module veb + +import os + +fn test_load_files_translations() { + os.chdir(os.dir(@FILE))! + + translations := load_tr_map() + + assert 'pt-br' in translations + assert 'en' in translations + + assert 'msg_hello' in translations['pt-br'] + assert 'msg_hello' in translations['en'] + + assert translations['pt-br']['msg_hello'] == 'Olá' + assert translations['en']['msg_hello'] == 'Hello' +} diff --git a/vlib/veb/translations/en.tr b/vlib/veb/translations/en.tr new file mode 100644 index 0000000000..edd397b8bc --- /dev/null +++ b/vlib/veb/translations/en.tr @@ -0,0 +1,2 @@ +msg_hello +Hello \ No newline at end of file diff --git a/vlib/veb/translations/pt-br.tr b/vlib/veb/translations/pt-br.tr new file mode 100644 index 0000000000..1316c93a6e --- /dev/null +++ b/vlib/veb/translations/pt-br.tr @@ -0,0 +1,2 @@ +msg_hello +Olá \ No newline at end of file