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