language -> @language: allow reference to local variables
parent
d96e16de20
commit
0e44198a8c
|
@ -12,7 +12,7 @@ macro __str(phrase)
|
|||
line = __source__.line,
|
||||
strid = phrase))
|
||||
return esc(quote
|
||||
get(get(i18n, I18N.language(), Dict()),
|
||||
get(get(i18n, @language, Dict()),
|
||||
$phrase, $phrase)
|
||||
end)
|
||||
end
|
||||
|
@ -102,7 +102,9 @@ macro translator(lang, name, email, copyright)
|
|||
end)
|
||||
end
|
||||
|
||||
@inline language() = "en"
|
||||
macro language()
|
||||
"en"
|
||||
end
|
||||
|
||||
export @__str, @translations, @translate,
|
||||
@translator, @write_po_files, lang_expand
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
_"hello"
|
||||
_"hi"
|
||||
_"hola"
|
||||
function return_hellos(req)
|
||||
(_"hello",
|
||||
_"hi",
|
||||
_"hola")
|
||||
end
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
_"first"
|
||||
_"second"
|
||||
_"third"
|
||||
function print_numbers(req)
|
||||
println.([_"first", _"second", _"third"])
|
||||
end
|
||||
|
|
17
test/test.jl
17
test/test.jl
|
@ -1,15 +1,15 @@
|
|||
push!(LOAD_PATH, realpath(".."))
|
||||
|
||||
using I18N
|
||||
@translations it en
|
||||
|
||||
# Define it before expanding any _"string"
|
||||
# Custom function used to get the program language.
|
||||
# Must return a 2-char language code
|
||||
req = Dict(:params => Dict(:lang => "it"))
|
||||
@inline function I18N.language()
|
||||
req[:params][:lang]
|
||||
macro language()
|
||||
return esc(:(req[:params][:lang]))
|
||||
end
|
||||
|
||||
@translations it en
|
||||
|
||||
@translate "it" "first" "primo"
|
||||
@translate "it" "third" "terzo"
|
||||
|
||||
|
@ -21,3 +21,10 @@ include("hello.jl")
|
|||
@translator "it" "Nicolò Balzarotti" "nicolo@nixo.xyz" "2020"
|
||||
|
||||
@write_po_files "Test" "0.0.0-dev" ["Nicolò Balzarotti <nicolo@nixo.xyz>"] "2020"
|
||||
|
||||
let req = Dict(:params => Dict(:lang => "it"))
|
||||
_"third"
|
||||
end
|
||||
|
||||
print_numbers(Dict(:params => Dict(:lang => "it")))
|
||||
return_hellos(Dict(:params => Dict(:lang => "it")))
|
||||
|
|
Loading…
Reference in New Issue