diff --git a/src/I18N.jl b/src/I18N.jl index 18d1a0c..566c246 100644 --- a/src/I18N.jl +++ b/src/I18N.jl @@ -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 diff --git a/test/hello.jl b/test/hello.jl index 31e646b..d6935e0 100644 --- a/test/hello.jl +++ b/test/hello.jl @@ -1,3 +1,5 @@ -_"hello" -_"hi" -_"hola" +function return_hellos(req) + (_"hello", + _"hi", + _"hola") +end diff --git a/test/numbers.jl b/test/numbers.jl index af4991f..b6b0559 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -1,3 +1,3 @@ -_"first" -_"second" -_"third" +function print_numbers(req) + println.([_"first", _"second", _"third"]) +end diff --git a/test/test.jl b/test/test.jl index cac79b5..4c1df25 100644 --- a/test/test.jl +++ b/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 "] "2020" + +let req = Dict(:params => Dict(:lang => "it")) + _"third" +end + +print_numbers(Dict(:params => Dict(:lang => "it"))) +return_hellos(Dict(:params => Dict(:lang => "it")))