Skip to content

Commit

Permalink
Merge pull request #63 from bausshf/master
Browse files Browse the repository at this point in the history
Added i18n placeholder functionality
  • Loading branch information
bausshf authored Mar 24, 2018
2 parents 2939d84 + 3acca27 commit f6200d9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 1 addition & 2 deletions data/i18n/messages.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import diamond.core.apptype;

static if (isWeb)
{

import diamond.http;

/// Alias for an associative array.
Expand All @@ -19,7 +18,7 @@ static if (isWeb)
private __gshared Language[string] _messages;

/// The default language.
private __gshared string _defaultLanguage;
package(diamond) __gshared string _defaultLanguage;

/**
* Sets the default language of the application.
Expand Down
4 changes: 3 additions & 1 deletion http/client.d
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ static if (isWeb)
{
if (_language is null)
{
_language = session.getValue!string(languageSessionKey, "");
import diamond.data.i18n.messages : _defaultLanguage;

_language = session.getValue!string(languageSessionKey, _defaultLanguage);
}

return _language;
Expand Down
5 changes: 4 additions & 1 deletion views/view.d
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ static if (!isWebApi)
mixin {{extensionEntry}}.extension;
});

onViewCtor();
static if (__traits(compiles, { onViewCtor();}))
{
onViewCtor();
}
}
}
else
Expand Down
21 changes: 20 additions & 1 deletion views/viewparser.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ static if (!isWebApi)

case ContentMode.appendContentPlaceholder:
{
viewCodeGeneration ~= parseAppendPlaceholderContent(part);
if (part.content[0] == '%' && part.content[$-1] == '%')
{
viewCodeGeneration ~= parseAppendTranslateContent(part);
}
else
{
viewCodeGeneration ~= parseAppendPlaceholderContent(part);
}
break;
}

Expand Down Expand Up @@ -160,6 +167,18 @@ static if (!isWebApi)
return appendFormat.format("getPlaceholder(`" ~ part.content ~ "`)");
}

/**
* Parses content that can be appended as i18n.
* Params:
* part = The part to parse.
* Returns:
* The appended result.
*/
string parseAppendTranslateContent(Part part)
{
return appendFormat.format("i18n.getMessage(super.client, \"" ~ part.content[1 .. $-1] ~ "\")");
}

/**
* Parses content that can be appended.
* Params:
Expand Down

0 comments on commit f6200d9

Please sign in to comment.