-
Notifications
You must be signed in to change notification settings - 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
Arguments: ["Joe", "world"]
| Translation | Result |
|---|---|
"Hello, {0}!" |
"Hello, Joe!" |
"Hello, {1}!" |
"Hello, world!" |
If the first argument is an object, you can print the values from the object rather than the object itself:
Arguments: [{ firstName: "Joe", lastName: "Cool" }]
| Translation | Result |
|---|---|
"Hello, {firstName}!" |
"Hello, Joe!" |
"Hello, Mr. {lastName}!" |
"Hello, Mr. Cool!" |
"Hello, {firstName} {lastName}!" |
"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:
Arguments: ["some other value here", { firstName: "Joe", lastName: "Cool" }]
| Translation | Result |
|---|---|
"Hello, {1.firstName}!" |
"Hello, Joe!" |
"Hello, Mr. {1.lastName}!" |
"Hello, Mr. Cool!" |
"Hello, {1.firstName} {1.lastName}!" |
"Hello, Joe Cool!" |
Translation: "I {likesVeggies?love:hate} vegetables!"
| Arguments | Result |
|---|---|
[{ likesVeggies: true }] |
"I love 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: "I ate {donutsEaten?{donutsEaten}:no} donuts!"
| Arguments | Result |
|---|---|
[{ donutsEaten: 0 }] |
"I ate 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: "I like animals.{favoriteAnimal? My favorite animal is a {favoriteAnimal}!}"
| Arguments | Result |
|---|---|
[{}] |
"I like animals." |
[{ favoriteAnimal: "fox" }] |
"I like animals. My favorite animal is a fox!" |
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: "Argument 0 is {0}. Escaped: {{Argument 0 is {0}.}}"
| Arguments | Result |
|---|---|
["foo"] |
"Argument 0 is foo. Escaped: Argument 0 is {0}." |
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)