You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,14 @@
2
2
3
3
All notable changes to this package will be documented in this file.
4
4
5
+
## [1.5.8] - 2025-09-26
6
+
7
+
### Fixed
8
+
9
+
- Fixed Smart Strings incorrectly evaluating global variables after the first selector. ([LOC-1252](https://issuetracker.unity3d.com/product/unity/issues/guid/LOC-1252))
10
+
- Simplified the string and asset picker so it does not include the side panels and customization options to match the object picker closer.
11
+
- The string and asset picker will now remember the previous layout state. ([LOC-1256](https://issuetracker.unity3d.com/product/unity/issues/guid/LOC-1256))
Conditional formatting occurs on any placeholder that contains a pipe character `|` after the colon `:`.
4
4
To invoke the [Conditional Formatter](xref:UnityEngine.Localization.SmartFormat.Extensions.ConditionalFormatter) explicitly use the name "conditional" or "cond". It can also be used implicitly when no name is provided.
The behavior of Conditional Formatter varies depending on the data type of the placeholder:
7
+
8
+
## Number
9
+
10
+
When you use a number type, such as integer or double, the value determines which item is selected from the choices list. If the value is not an integer, it is rounded down to the nearest whole number—the floor value is used as the index.
11
+
12
+
If the value is negative or exceeds the number of available choices, the default option is returned.
13
+
14
+
The following shows the example outputs of the number type:
You can define more complex comparisons with the following syntax:
28
+
29
+
- Each parameter is separated by a `|`.
30
+
- A comparison is followed by a ?, then the corresponding output text.
31
+
- The final (default) entry does not include a comparison or a ?; it serves as the fallback if no conditions are met.
17
32
18
33
Each parameter is separated by `|`. The comparison is followed by a `?` and then the text. The last (default) entry does not contain a comparison nor a `?`.
19
34
20
35
The following comparisons are supported:
21
36
22
-
-**>=**
23
-
-**>**
24
-
-**=**
25
-
-**<**
26
-
-**<=**
27
-
-**!=**
37
+
|**Operator**|**Description**|
38
+
| ------------ | ----------- |
39
+
|**>=**| greater than or equal to |
40
+
|**>**| greater than |
41
+
|**=**| equal to |
42
+
|**<**| less than |
43
+
|**<=**| less than or equal to |
44
+
|**!=**| not equal to |
28
45
29
46
To combine comparisons, use `&` for AND or `/` for OR.
30
47
@@ -51,3 +68,85 @@ To combine comparisons, use `&` for AND or `/` for OR.
51
68
</tr>
52
69
53
70
</table>
71
+
72
+
## Booleans
73
+
74
+
When you use a boolean data type, the value determines the output.
75
+
If the value is true, the first item in the output choices is used. If the value is false, the second item is selected.
When you use a string data type, the value itself is output as long as it is not null or an empty string (""). If the value is null or empty, the default choice is used instead.
87
+
88
+
Syntax: `{0:cond:default|null or empty}`
89
+
90
+
|**Syntax**|**Value**|**Output**|
91
+
| ---------- | --------- | ---------- |
92
+
| The string is {0:not null or empty|null or empty} | "Some text" | "The string is not null or empty" |
93
+
| The string is {0:not null or empty|null or empty} | "" | "The string is null or empty" |
94
+
| Text: {0:{0}\|No text to display} | "Hello World" | "Text: Hello World" |
95
+
| Text: {0:{0}\|No text to display} | null | "No text to display" |
96
+
| Text: {0:{0}\|No text to display} | "" | "No text to display" |
97
+
98
+
## DateTime or DateTimeOffset
99
+
100
+
When you use DateTime or DateTimeOffset data types, the value is compared to the **current calendar date** (year, month, and day only).
101
+
102
+
If there are three output choices, the index values are:
103
+
104
+
- 0 for a past date
105
+
- 1 for today
106
+
- 2 for a future date
107
+
108
+
Syntax: `{0:cond:past date|today|future date}`
109
+
110
+
If there are two output choices, the index values are:
111
+
112
+
- 0 for today or a past date
113
+
- 1 for a future date
114
+
115
+
Syntax: `{0:cond:today or past date|future date}`
116
+
117
+
|**Syntax**|**Value**|**Output**|
118
+
| ---------- | --------- | ---------- |
119
+
| My birthday {0:was yesterday\|is today\|will be tomorrow} | DateTime.Now.AddDays(1) | "My birthday was yesterday" |
120
+
| My birthday {0:was yesterday\|is today\|will be tomorrow} | DateTime.Now | "My birthday is today" |
121
+
| My birthday {0:was yesterday\|is today\|will be tomorrow} | DateTime.Now.AddDays(-1) | "My birthday will be tomorrow" |
122
+
123
+
## TimeSpan
124
+
125
+
When using the TimeSpan data type, the value is compared to `TimeSpan.Zero`.
126
+
127
+
If there are three output choices, the index values are:
If there are two output choices, the index values are:
136
+
137
+
- 0 for a negative or zero duration
138
+
- 1 for a positive duration
139
+
140
+
Syntax: `{0:cond:negative or zero duration|positive duration}`
141
+
142
+
|**Syntax**|**Value**|**Output**|
143
+
| ---------- | --------- | ---------- |
144
+
| The event {0:cond:will start in {Hours} hours\|is now\|was {Hours} hours ago} | TimeSpan.Zero.Add(new TimeSpan(-2,0,0)) | "The event will start in 2 hours" |
145
+
| The event {0:cond:will start in {Hours} hours\|is now\|was {Hours} hours ago} | TimeSpan.Zero | "The event is now" |
146
+
| The event {0:cond:will start in {Hours} hours\|is now\|was {Hours} hours ago} | TimeSpan.Zero.Add(new TimeSpan(3,0,0)) | "The event was 3 hours ago" |
147
+
148
+
## Other (object)
149
+
150
+
If the data type is not one of the types listed above, it is treated as a general object and evaluated against null. If the value is not null, the choice at index 0 is used. If the value is null, the choice at index 1 is used instead.
Copy file name to clipboardExpand all lines: Documentation~/Smart/Plural-Formatter.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,3 +68,15 @@ To determine which plural rules to apply, the Plural Localization Formatter uses
68
68
</tr>
69
69
70
70
</table>
71
+
72
+
## Custom plural rules
73
+
74
+
You can add custom plural rules to replace existing ones or create new rules. Sometimes, you might want to use a custom ruleset for particular situations without changing the default rules everywhere. To do this, define a new plural rule and reference it directly in your smart string with brackets.
75
+
76
+
The following example defines a custom plural rule for Russian that uses two plural forms instead of the standard three. When the pluralization logic requires the third form, this rule redirects it to the second form. This provides more precise control in scenarios where only two plural variations are needed.
0 commit comments