Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't distinguish trans and blocktrans in internal code; fix opts.

Append `locale` compile-time option value to `blocktrans_locales`.
  • Loading branch information...
commit 9f5e694da9fe6e0f6814c01d537f39b4b934c542 1 parent 1caea05
@seriyps seriyps authored kaos committed
Showing with 17 additions and 10 deletions.
  1. +2 −2 include/erlydtl_ext.hrl
  2. +15 −8 src/erlydtl_compiler.erl
View
4 include/erlydtl_ext.hrl
@@ -8,8 +8,8 @@
-record(dtl_context, {
local_scopes = [],
block_dict = dict:new(),
- blocktrans_fun = none,
- blocktrans_locales = [],
+ trans_fun = none,
+ trans_locales = [],
auto_escape = off,
doc_root = "",
parse_trail = [],
View
23 src/erlydtl_compiler.erl
@@ -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, Module, Options) ->
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{
all_options = Options,
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,
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),
- 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),
reader = proplists:get_value(reader, Options, Ctx#dtl_context.reader),
compiler_options = proplists:append_values(compiler_options, Options),
binary_strings = proplists:get_value(binary_strings, Options, Ctx#dtl_context.binary_strings),
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),
is_compiling_dir = ParseTrail == [],
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)),
{{DefaultAst, AstInfo}, TreeWalker2} = body_ast(Contents, NewContext, TreeWalker1),
MergedInfo = merge_info(AstInfo, ArgInfo),
- case Context#dtl_context.blocktrans_fun of
+ case Context#dtl_context.trans_fun of
none ->
%% translate in runtime
blocktrans_runtime_ast({DefaultAst, MergedInfo}, TreeWalker2, SourceText, Contents, NewContext);
@@ -1219,7 +1226,7 @@ blocktrans_ast(ArgList, Contents, Context, TreeWalker) ->
{merge_info(ThisAstInfo, AstInfoAcc), TreeWalker3,
[erl_syntax:clause([erl_syntax:string(Locale)], none, [ThisAst])|ClauseAcc]}
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"),
Clauses ++ [erl_syntax:clause([erl_syntax:underscore()], none, [DefaultAst])]),
{{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
undefined ->
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);
_ -> compiletime_trans_ast(UnescapedStr, AstInfo, Context, TreeWalker)
end;
@@ -1275,8 +1282,8 @@ runtime_trans_ast(ValueAst, AstInfo, TreeWalker) ->
{{StringLookupAst, AstInfo}, TreeWalker}.
compiletime_trans_ast(String, AstInfo,
- #dtl_context{blocktrans_fun=TFun,
- blocktrans_locales=TLocales}=Context,
+ #dtl_context{trans_fun=TFun,
+ trans_locales=TLocales}=Context,
TreeWalker) ->
{{DefaultAst, Info1}, TWalker1} = Default = string_ast(String, Context, TreeWalker),
DefaultClauseAst = erl_syntax:clause([erl_syntax:underscore()], none, [DefaultAst]), %or runtime trans?
Please sign in to comment.
Something went wrong with that request. Please try again.