Changes
Jump to navigation
Jump to search
← Older edit
Newer edit →
Modding:Modder Guide/APIs
(view source)
Revision as of 00:44, 29 May 2017
321 bytes added
,
00:44, 29 May 2017
→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>
Pathoschild
manager
8,548
edits
Navigation menu
Personal tools
Create account
Log in
Namespaces
Modding
Discussion
Variants
Views
Read
View source
View history
More
Search
Navigation
Main page
Recent changes
Admin noticeboard
Help Editing
Random page
Official Links
Official Site
Official Forums
Official Merchandise
Discord
Reddit
Tools
Upload file
Special pages
Printable version