Skip to content

Commit

Permalink
Output warning for non-functional Diet translations.
Browse files Browse the repository at this point in the history
Outputs a CT warning whenever a "&" translation suffix is used without a valid translation context.
  • Loading branch information
s-ludwig committed Apr 17, 2015
1 parent c9f3e3d commit ac6d4ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/vibe/templ/diet.d
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ private class OutputContext {
Line m_line = Line(null, -1, null);
size_t m_baseIndent;
bool m_isHTML5;
bool warnTranslationContext = false;

this(size_t base_indent = 0)
{
Expand Down Expand Up @@ -488,6 +489,8 @@ private struct DietCompiler(TRANSLATE...)
auto output = new OutputContext(base_indent);
buildWriter(output, 0);
assert(output.m_nodeStack.length == 0, "Template writer did not consume all nodes!?");
if (output.warnTranslationContext)
output.writeCodeLine(`pragma(msg, "Warning: No translation context found, ignoring '&' suffixes. Note that you have to use @translationContext in conjunction with vibe.web.web.render() (vibe.http.server.render() does not work) to enable translation support.");`);
return output.m_result;
}

Expand Down Expand Up @@ -854,7 +857,9 @@ private struct DietCompiler(TRANSLATE...)
output.writeExpr(ctstrip(line[i+2 .. line.length]));
} else {
string rawtext = line[i .. line.length];
static if (TRANSLATE.length > 0) if (ws_type.isTranslated) rawtext = TRANSLATE[0](rawtext);
static if (TRANSLATE.length > 0) {
if (ws_type.isTranslated) rawtext = TRANSLATE[0](rawtext);
} else if (ws_type.isTranslated) output.warnTranslationContext = true;
if (hasInterpolations(rawtext)) {
buildInterpolatedString(output, rawtext);
} else {
Expand Down

0 comments on commit ac6d4ff

Please sign in to comment.