-
Couldn't load subscription status.
- Fork 1
Translation Interpolation
All translations are passed through Wayward's "interpolation" system. This system allows for translations to reference "arguments", for example, mapping {0} to "A Stone Shovel", along with many other features. This page will serve as an overview for all supported interpolations, or segments, and other information on the interpolation system.
A segment in Wayward is defined as the string between an opening curly brace { and a closing curly brace }. For example, valid segments include {0}, {0?{0}}, {DictionaryId:TranslationId}.
- Color Segment
- Bold Segment
- Italic Segment
- Underline Segment
- Heading Segment
- List Segment
- Number Segment
- Noun Reformatting Segment
Say you want to include curly braces or other content which normally would be interpolated. When that is the case, you can "escape" it.
| Translation | Arguments | Result |
|---|---|---|
"Arg 0 is {0}. Escaped: Arg 0 is \\{0\\}." |
"foo" |
"Arg 0 is foo. Escaped: Arg 0 is {0}." |
| Translation | Arguments | Result |
|---|---|---|
"Hello, {0}!" |
"Joe", "world"
|
"Hello, Joe!" |
"Hello, {1}!" |
"Joe", "world"
|
"Hello, world!" |
If the first argument is an object, you can print the values from the object rather than the object itself:
Arguments:
| Translation | Arguments | Result |
|---|---|---|
"Hello, {firstName}!" |
{ firstName: "Joe", lastName: "Cool" } |
"Hello, Joe!" |
"Hello, Mr. {lastName}!" |
{ firstName: "Joe", lastName: "Cool" } |
"Hello, Mr. Cool!" |
"Hello, {firstName} {lastName}!" |
{ firstName: "Joe", lastName: "Cool" } |
"Hello, Joe Cool!" |
If you want to get values from an object that is not the first argument, you can specify which argument you want with the "index". The index starts at 0, so the second argument would be at index 1:
| Translation | Arguments | Result |
|---|---|---|
"Hello, {1.firstName}!" |
other value, { firstName: "Joe", lastName: "Cool" }
|
"Hello, Joe!" |
"Hello, Mr. {1.lastName}!" |
other value, { firstName: "Joe", lastName: "Cool" }
|
"Hello, Mr. Cool!" |
"Hello, {1.firstName} {1.lastName}!" |
other value, { firstName: "Joe", lastName: "Cool" }
|
"Hello, Joe Cool!" |
| Translation | Arguments | Result |
|---|---|---|
"I {likesVeggies?love:hate} vegetables!" |
{ likesVeggies: true } |
"I love vegetables!" |
"I {likesVeggies?love:hate} vegetables!" |
{ likesVeggies: false } |
"I hate vegetables!" |
JavaScript has the concept of "truthy" and "falsy" values, where "falsy" values are false, null, undefined, 0, NaN, and "", and "truthy" values are all others. The conditional interpolation takes an argument and, if it's a truthy value, uses the string before the :. If it's a falsy value, it uses the string after the :.
You can combine the argument interpolation and the conditional interpolation to produce strings such as the following:
| Translation | Arguments | Result |
|---|---|---|
"I ate {donutsEaten?{donutsEaten}:no} donuts!" |
{ donutsEaten: 0 } |
"I ate no donuts!" |
"I ate {donutsEaten?{donutsEaten}:no} donuts!" |
{ donutsEaten: 5 } |
"I ate 5 donuts!" |
You can also skip the : in the conditional segment if you don't need the "or else" text.
| Translation | Arguments | Result |
|---|---|---|
"Animals?{favorite? My favorite's a {favorite}!}" |
{} |
"Animals?" |
"Animals?{favorite? My favorite's a {favorite}!}" |
{ favorite: "fox" } |
"Animals? My favorite's a fox!" |
The conditional segment actually supports checking a wider range of things than the truthiness of an argument.
You can actually provide a list of checks:
| Translation | Arguments | Result |
|---|---|---|
"I {love&puppies?love puppies:hate everything}!" |
{} |
"I hate everything!" |
"I {love&puppies?love puppies:hate everything}!" |
{ love: false, puppies: true } |
"I hate everything!" |
"I {love&puppies?love puppies:hate everything}!" |
{ love: true, puppies: true } |
"I love puppies!" |
Here we use the & operator for multiple checks, but , and are both valid as well, ie {check1,check2?both are true:neither are true} or {check1 check2?both are true:neither are true}
For each check, rather than just checking whether a value is truthy, you can do a wide range of checks, such as equivalence (= or !=), and comparisons (< or > or <= or >=).
| Translation | Arguments | Result |
|---|---|---|
"That is {thing=cool?pretty neat:kinda lame}!" |
{} |
"That is kinda lame!" |
"That is {thing=cool?pretty neat:kinda lame}!" |
{ thing: true } |
"That is kinda lame!" |
"That is {thing=cool?pretty neat:kinda lame}!" |
{ thing: "cool" } |
"That is pretty neat!" |
"You are {bananas<0?in banana debt:rich with bananas}!" |
{ bananas: -5 } |
"You are in banana debt!" |
"You are {bananas<0?in banana debt:rich with bananas}!" |
{ bananas: 5 } |
"You are rich with bananas!" |
Note: The examples in this section cannot contain colors due to the limitations of GitHub markdown, so you'll have to use your imagination.
The color segment is signified with a leading #, and the text to colorize is signified with a colon :.
You can specify a hex color with the segment. If you do a hex color, it can be in the format RGB, RRGGBB, RGBA, or RRGGBBAA.
| Translation | Result |
|---|---|
"{#f00:This text will be red.}" |
"This text will be red." |
You can also specify CSS variables. If you do a CSS variable color, it must begin with --.
To see all CSS variables defined, see: Viewing a full list of CSS variables
| Translation | Result |
|---|---|
"{#--color-bad:This text will be red.}" |
"This text will be red." |
"{#--color-good:This text will be lime.}" |
"This text will be lime." |
Finally, no matter what you provide for the color value, you can also interpolate within it. For example, you can reference a color variable using an argument as part of the color variable's name.
| Translation | Arguments | Result |
|---|---|---|
"{#{0}:This text will be blue.}" |
"00f" |
"This text will be blue." |
"{#{0}:This text will be green.}" |
"00ff00" |
"This text will be green." |
"{#--color-npc-{0}:This text will be red.}" |
"hostile" |
"This text will be red." |
"{#--color-npc-{0}:This text will be green.}" |
"friendly" |
"This text will be green." |
Formats a list from all the provided values. List formatting uses the translations:
Misc.ListItemSeparatorMisc.AAndBMisc.AListAndB
| Translation | Arguments | Result |
|---|---|---|
"Today I ate {...}" |
"apples", "bananas", "pears"
|
"Today I ate apples, bananas, and pears." |
You can also set a custom "concatenator" by providing text after the ellipsis ...:
| Translation | Arguments | Result |
|---|---|---|
"Today I ate {...&}" |
"apples", "bananas", "pears"
|
"Today I ate apples&bananas&pears." |
You can also format a list from array arguments by specifying the argument location before the ellipsis ...:
| Translation | Arguments | Result |
|---|---|---|
"Today I ate {1...}" |
other value, ["apples", "bananas", "pears"]
|
"Today I ate apples, bananas, and pears." |
Getting Started
- Introduction
- Prerequisites
+mod create&+mod update- mod.json
- Extracting Assets
- Resources & Examples
- Frequently Asked Questions
Mod Content
Script Documentation
- Using Translations
- Registrations
- Event Handlers
- Injection
- Adding Items
- Adding Doodads
- Adding Creatures
- Adding Magical Properties
- Actions & Multiplayer
- Adding Dialogs
- Context Menu/Action Bar Actions
- Inter-mod Registries
(apologies for all the missing guides, we'll get to them at some point)