Open main menu
Home
Random
Log in
Settings
About Stardew Valley Wiki
Disclaimers
Stardew Valley Wiki
Search
Changes
← 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,549
edits