|
@@ -424,6 +424,14 @@ init_context(ParseTrail, DefDir, Module, Options) when is_list(Module) ->
|
|
init_context(ParseTrail, DefDir, list_to_atom(Module), Options);
|
|
init_context(ParseTrail, DefDir, list_to_atom(Module), Options);
|
|
init_context(ParseTrail, DefDir, Module, Options) ->
|
|
init_context(ParseTrail, DefDir, Module, Options) ->
|
|
Ctx = #dtl_context{},
|
|
Ctx = #dtl_context{},
|
|
|
|
+ Locale = proplists:get_value(locale, Options),
|
|
|
|
+ BlocktransLocales = proplists:get_value(blocktrans_locales, Options),
|
|
|
|
+ TransLocales = case {Locale, BlocktransLocales} of
|
|
|
|
+ {undefined, undefined} -> Ctx#dtl_context.trans_locales;
|
|
|
|
+ {undefined, Val} when Val =/= undefined -> Val;
|
|
|
|
+ {Val, undefined} when Val =/= undefined -> [Val];
|
|
|
|
+ _ -> ordsets:add_element(Locale, ordsets:from_list(BlocktransLocales))
|
|
|
|
+ end,
|
|
Context = #dtl_context{
|
|
Context = #dtl_context{
|
|
all_options = Options,
|
|
all_options = Options,
|
|
auto_escape = case proplists:get_value(auto_escape, Options, true) of
|
|
auto_escape = case proplists:get_value(auto_escape, Options, true) of
|
|
@@ -440,14 +448,13 @@ init_context(ParseTrail, DefDir, Module, Options) ->
|
|
custom_tags_dir, Options,
|
|
custom_tags_dir, Options,
|
|
filename:join([erlydtl_deps:get_base_dir(), "priv", "custom_tags"])),
|
|
filename:join([erlydtl_deps:get_base_dir(), "priv", "custom_tags"])),
|
|
custom_tags_modules = proplists:get_value(custom_tags_modules, Options, Ctx#dtl_context.custom_tags_modules),
|
|
custom_tags_modules = proplists:get_value(custom_tags_modules, Options, Ctx#dtl_context.custom_tags_modules),
|
|
- blocktrans_fun = proplists:get_value(blocktrans_fun, Options, Ctx#dtl_context.blocktrans_fun),
|
|
|
|
- blocktrans_locales = proplists:get_value(blocktrans_locales, Options, Ctx#dtl_context.blocktrans_locales),
|
|
|
|
|
|
+ trans_fun = proplists:get_value(blocktrans_fun, Options, Ctx#dtl_context.trans_fun),
|
|
|
|
+ trans_locales = TransLocales,
|
|
vars = proplists:get_value(vars, Options, Ctx#dtl_context.vars),
|
|
vars = proplists:get_value(vars, Options, Ctx#dtl_context.vars),
|
|
reader = proplists:get_value(reader, Options, Ctx#dtl_context.reader),
|
|
reader = proplists:get_value(reader, Options, Ctx#dtl_context.reader),
|
|
compiler_options = proplists:append_values(compiler_options, Options),
|
|
compiler_options = proplists:append_values(compiler_options, Options),
|
|
binary_strings = proplists:get_value(binary_strings, Options, Ctx#dtl_context.binary_strings),
|
|
binary_strings = proplists:get_value(binary_strings, Options, Ctx#dtl_context.binary_strings),
|
|
force_recompile = proplists:get_bool(force_recompile, Options),
|
|
force_recompile = proplists:get_bool(force_recompile, Options),
|
|
- %% convert to blocktrans_locales locale = proplists:get_value(locale, Options, Ctx#dtl_context.locale),
|
|
|
|
verbose = proplists:get_value(verbose, Options, Ctx#dtl_context.verbose),
|
|
verbose = proplists:get_value(verbose, Options, Ctx#dtl_context.verbose),
|
|
is_compiling_dir = ParseTrail == [],
|
|
is_compiling_dir = ParseTrail == [],
|
|
extension_module = proplists:get_value(extension_module, Options, Ctx#dtl_context.extension_module),
|
|
extension_module = proplists:get_value(extension_module, Options, Ctx#dtl_context.extension_module),
|
|
@@ -1203,7 +1210,7 @@ blocktrans_ast(ArgList, Contents, Context, TreeWalker) ->
|
|
SourceText = lists:flatten(erlydtl_unparser:unparse(Contents)),
|
|
SourceText = lists:flatten(erlydtl_unparser:unparse(Contents)),
|
|
{{DefaultAst, AstInfo}, TreeWalker2} = body_ast(Contents, NewContext, TreeWalker1),
|
|
{{DefaultAst, AstInfo}, TreeWalker2} = body_ast(Contents, NewContext, TreeWalker1),
|
|
MergedInfo = merge_info(AstInfo, ArgInfo),
|
|
MergedInfo = merge_info(AstInfo, ArgInfo),
|
|
- case Context#dtl_context.blocktrans_fun of
|
|
|
|
|
|
+ case Context#dtl_context.trans_fun of
|
|
none ->
|
|
none ->
|
|
%% translate in runtime
|
|
%% translate in runtime
|
|
blocktrans_runtime_ast({DefaultAst, MergedInfo}, TreeWalker2, SourceText, Contents, NewContext);
|
|
blocktrans_runtime_ast({DefaultAst, MergedInfo}, TreeWalker2, SourceText, Contents, NewContext);
|
|
@@ -1219,7 +1226,7 @@ blocktrans_ast(ArgList, Contents, Context, TreeWalker) ->
|
|
{merge_info(ThisAstInfo, AstInfoAcc), TreeWalker3,
|
|
{merge_info(ThisAstInfo, AstInfoAcc), TreeWalker3,
|
|
[erl_syntax:clause([erl_syntax:string(Locale)], none, [ThisAst])|ClauseAcc]}
|
|
[erl_syntax:clause([erl_syntax:string(Locale)], none, [ThisAst])|ClauseAcc]}
|
|
end
|
|
end
|
|
- end, {MergedInfo, TreeWalker2, []}, Context#dtl_context.blocktrans_locales),
|
|
|
|
|
|
+ end, {MergedInfo, TreeWalker2, []}, Context#dtl_context.trans_locales),
|
|
Ast = erl_syntax:case_expr(erl_syntax:variable("_CurrentLocale"),
|
|
Ast = erl_syntax:case_expr(erl_syntax:variable("_CurrentLocale"),
|
|
Clauses ++ [erl_syntax:clause([erl_syntax:underscore()], none, [DefaultAst])]),
|
|
Clauses ++ [erl_syntax:clause([erl_syntax:underscore()], none, [DefaultAst])]),
|
|
{{Ast, FinalAstInfo#ast_info{ translated_blocks = [SourceText] }}, FinalTreeWalker}
|
|
{{Ast, FinalAstInfo#ast_info{ translated_blocks = [SourceText] }}, FinalTreeWalker}
|
|
@@ -1256,7 +1263,7 @@ translated_ast({string_literal, _, String}, Context, TreeWalker) ->
|
|
case call_extension(Context, translate_ast, [UnescapedStr, Context, TreeWalker]) of
|
|
case call_extension(Context, translate_ast, [UnescapedStr, Context, TreeWalker]) of
|
|
undefined ->
|
|
undefined ->
|
|
AstInfo = #ast_info{translatable_strings = [UnescapedStr]},
|
|
AstInfo = #ast_info{translatable_strings = [UnescapedStr]},
|
|
- case Context#dtl_context.blocktrans_fun of
|
|
|
|
|
|
+ case Context#dtl_context.trans_fun of
|
|
none -> runtime_trans_ast(erl_syntax:string(UnescapedStr), AstInfo, TreeWalker);
|
|
none -> runtime_trans_ast(erl_syntax:string(UnescapedStr), AstInfo, TreeWalker);
|
|
_ -> compiletime_trans_ast(UnescapedStr, AstInfo, Context, TreeWalker)
|
|
_ -> compiletime_trans_ast(UnescapedStr, AstInfo, Context, TreeWalker)
|
|
end;
|
|
end;
|
|
@@ -1275,8 +1282,8 @@ runtime_trans_ast(ValueAst, AstInfo, TreeWalker) ->
|
|
{{StringLookupAst, AstInfo}, TreeWalker}.
|
|
{{StringLookupAst, AstInfo}, TreeWalker}.
|
|
|
|
|
|
compiletime_trans_ast(String, AstInfo,
|
|
compiletime_trans_ast(String, AstInfo,
|
|
- #dtl_context{blocktrans_fun=TFun,
|
|
|
|
- blocktrans_locales=TLocales}=Context,
|
|
|
|
|
|
+ #dtl_context{trans_fun=TFun,
|
|
|
|
+ trans_locales=TLocales}=Context,
|
|
TreeWalker) ->
|
|
TreeWalker) ->
|
|
{{DefaultAst, Info1}, TWalker1} = Default = string_ast(String, Context, TreeWalker),
|
|
{{DefaultAst, Info1}, TWalker1} = Default = string_ast(String, Context, TreeWalker),
|
|
DefaultClauseAst = erl_syntax:clause([erl_syntax:underscore()], none, [DefaultAst]), %or runtime trans?
|
|
DefaultClauseAst = erl_syntax:clause([erl_syntax:underscore()], none, [DefaultAst]), %or runtime trans?
|