Changes

Jump to navigation Jump to search
→‎Translation: update for draft API changes
Line 443: Line 443:  
<source lang="c#">
 
<source lang="c#">
 
// read a simple translation
 
// read a simple translation
string label = helper.Translate("item-type.label");
+
string label = helper.Translation.Get("item-type.label");
   −
// read a translation which uses tokens
+
// read a translation which uses tokens (accepts an anonymous object, dictionary, or model)
string text = helper.Translate("item-type.fruit-tree").Tokens(new { fruitName = "apple" });
+
string text = helper.Translation.Get("item-type.fruit-tree", new { fruitName = "apple" });
 
</source>
 
</source>
   Line 452: Line 452:  
<source lang="c#">
 
<source lang="c#">
 
// use fluent chain
 
// use fluent chain
string text = helper.Translate(key).Tokens(tokens).Assert();
+
string text = helper.Translate(key).Tokens(tokens).Tokens(moreTokens).Assert();
 +
</source>
 +
 
 +
If your code has a lot of translation calls, you can make it less verbose by aliasing the translation helper:
 +
<source lang="c#">
 +
var i18n = helper.Translation;
 +
 
 +
i18n.Get("item-type.fruit-tree", new { fruitName = i18n.Get("apple") });
 
</source>
 
</source>
  
manager
8,548

edits

Navigation menu