mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
veb: fix key value and translation file name (#23203)
This commit is contained in:
parent
05cbbfbabc
commit
939d243b5e
@ -22,7 +22,7 @@ struct TrData {
|
|||||||
// m['en']['house'] == 'House'
|
// m['en']['house'] == 'House'
|
||||||
fn load_tr_map() map[string]map[string]string {
|
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
|
// 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{}
|
mut res := map[string]map[string]string{}
|
||||||
for tr_path in files {
|
for tr_path in files {
|
||||||
lang := fetch_lang_from_tr_path(tr_path)
|
lang := fetch_lang_from_tr_path(tr_path)
|
||||||
@ -35,7 +35,7 @@ fn load_tr_map() map[string]map[string]string {
|
|||||||
// println('val="${val}"')
|
// println('val="${val}"')
|
||||||
nl_pos := s.index('\n') or { continue }
|
nl_pos := s.index('\n') or { continue }
|
||||||
key := s[..nl_pos]
|
key := s[..nl_pos]
|
||||||
val := s[nl_pos..]
|
val := s[nl_pos + 1..]
|
||||||
// v := vals[i + 1]
|
// v := vals[i + 1]
|
||||||
// println('key="${key}" => val="${v}"')
|
// println('key="${key}" => val="${v}"')
|
||||||
res[lang][key] = val
|
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 {
|
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
|
// Used by %key in templates
|
||||||
|
18
vlib/veb/tr_test.v
Normal file
18
vlib/veb/tr_test.v
Normal file
@ -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
vlib/veb/translations/en.tr
Normal file
2
vlib/veb/translations/en.tr
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
msg_hello
|
||||||
|
Hello
|
2
vlib/veb/translations/pt-br.tr
Normal file
2
vlib/veb/translations/pt-br.tr
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
msg_hello
|
||||||
|
Olá
|
Loading…
x
Reference in New Issue
Block a user