Skip to content

Commit

Permalink
veb: fix key value and translation file name (vlang#23203)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ddiidev authored Dec 19, 2024
1 parent 05cbbfb commit 939d243
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions vlib/veb/tr.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions vlib/veb/tr_test.v
Original file line number Diff line number Diff line change
@@ -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'
}
2 changes: 2 additions & 0 deletions vlib/veb/translations/en.tr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msg_hello
Hello
2 changes: 2 additions & 0 deletions vlib/veb/translations/pt-br.tr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
msg_hello
Olá

0 comments on commit 939d243

Please sign in to comment.