@quenty/localizedtextutils 12.17.0 → 12.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +6 -6
- package/src/Shared/LocalizedTextUtils.lua +82 -44
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [12.17.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/localizedtextutils@12.17.0...@quenty/localizedtextutils@12.17.1) (2025-04-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [12.17.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/localizedtextutils@12.16.2...@quenty/localizedtextutils@12.17.0) (2025-04-02)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/localizedtextutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/localizedtextutils",
|
|
3
|
-
"version": "12.17.
|
|
3
|
+
"version": "12.17.1",
|
|
4
4
|
"description": "Localized text utils which changes translationKey structures to shared locations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@quenty/attributeutils": "^14.17.
|
|
32
|
-
"@quenty/loader": "^10.8.
|
|
33
|
-
"@quenty/promisemaid": "^5.10.
|
|
34
|
-
"@quenty/rx": "^13.17.
|
|
31
|
+
"@quenty/attributeutils": "^14.17.1",
|
|
32
|
+
"@quenty/loader": "^10.8.1",
|
|
33
|
+
"@quenty/promisemaid": "^5.10.2",
|
|
34
|
+
"@quenty/rx": "^13.17.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
37
37
|
}
|
|
@@ -17,6 +17,7 @@ local LocalizedTextUtils = {}
|
|
|
17
17
|
@type TranslationArgs { [string]: LocalizedTextData | number | string }
|
|
18
18
|
@within LocalizedTextUtils
|
|
19
19
|
]=]
|
|
20
|
+
export type TranslationArgs = { [string]: LocalizedTextData | number | string }
|
|
20
21
|
|
|
21
22
|
--[=[
|
|
22
23
|
Valid localized text data
|
|
@@ -25,6 +26,10 @@ local LocalizedTextUtils = {}
|
|
|
25
26
|
.translationArgs TranslationArgs
|
|
26
27
|
@within LocalizedTextUtils
|
|
27
28
|
]=]
|
|
29
|
+
export type LocalizedTextData = {
|
|
30
|
+
translationKey: string,
|
|
31
|
+
translationArgs: TranslationArgs,
|
|
32
|
+
}
|
|
28
33
|
|
|
29
34
|
--[=[
|
|
30
35
|
Creates a new localizedtextdata
|
|
@@ -32,13 +37,13 @@ local LocalizedTextUtils = {}
|
|
|
32
37
|
@param translationArgs TranslationArgs
|
|
33
38
|
@return LocalizedTextData
|
|
34
39
|
]=]
|
|
35
|
-
function LocalizedTextUtils.create(translationKey, translationArgs)
|
|
40
|
+
function LocalizedTextUtils.create(translationKey: string, translationArgs: TranslationArgs): LocalizedTextData
|
|
36
41
|
assert(type(translationKey) == "string", "Bad translationKey")
|
|
37
42
|
assert(type(translationArgs) == "table" or translationArgs == nil, "Bad translationArgs")
|
|
38
43
|
|
|
39
44
|
return {
|
|
40
|
-
translationKey = translationKey
|
|
41
|
-
translationArgs = translationArgs
|
|
45
|
+
translationKey = translationKey,
|
|
46
|
+
translationArgs = translationArgs,
|
|
42
47
|
}
|
|
43
48
|
end
|
|
44
49
|
|
|
@@ -47,11 +52,10 @@ end
|
|
|
47
52
|
@param data any
|
|
48
53
|
@return boolean
|
|
49
54
|
]=]
|
|
50
|
-
function LocalizedTextUtils.isLocalizedText(data)
|
|
55
|
+
function LocalizedTextUtils.isLocalizedText(data: any): boolean
|
|
51
56
|
return type(data) == "table"
|
|
52
57
|
and type(data.translationKey) == "string"
|
|
53
|
-
and (type(data.translationArgs) == "table"
|
|
54
|
-
or data.translationArgs == nil)
|
|
58
|
+
and (type(data.translationArgs) == "table" or data.translationArgs == nil)
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
--[=[
|
|
@@ -62,20 +66,29 @@ end
|
|
|
62
66
|
@param extraArgs table?
|
|
63
67
|
@return string
|
|
64
68
|
]=]
|
|
65
|
-
function LocalizedTextUtils.formatByKeyRecursive(
|
|
69
|
+
function LocalizedTextUtils.formatByKeyRecursive(
|
|
70
|
+
translator: Translator,
|
|
71
|
+
translationKey: string,
|
|
72
|
+
translationArgs: TranslationArgs,
|
|
73
|
+
extraArgs
|
|
74
|
+
)
|
|
66
75
|
assert(translator, "Bad translator")
|
|
67
76
|
assert(type(translationKey) == "string", "Bad translationKey")
|
|
68
77
|
assert(type(translationArgs) == "table" or translationArgs == nil, "Bad translationArgs")
|
|
69
78
|
|
|
70
79
|
local formattedArgs = {}
|
|
71
80
|
if translationArgs then
|
|
72
|
-
for name, value in
|
|
81
|
+
for name, value in translationArgs do
|
|
73
82
|
if type(value) == "table" then
|
|
74
83
|
assert(value.translationKey, "Table, but no translationKey")
|
|
75
84
|
|
|
76
85
|
if value.translationArgs then
|
|
77
|
-
formattedArgs[name] = LocalizedTextUtils
|
|
78
|
-
|
|
86
|
+
formattedArgs[name] = LocalizedTextUtils.formatByKeyRecursive(
|
|
87
|
+
translator,
|
|
88
|
+
value.translationKey,
|
|
89
|
+
value.translationArgs,
|
|
90
|
+
extraArgs
|
|
91
|
+
)
|
|
79
92
|
else
|
|
80
93
|
formattedArgs[name] = translator:FormatByKey(value.translationKey)
|
|
81
94
|
end
|
|
@@ -86,7 +99,7 @@ function LocalizedTextUtils.formatByKeyRecursive(translator, translationKey, tra
|
|
|
86
99
|
end
|
|
87
100
|
|
|
88
101
|
if extraArgs then
|
|
89
|
-
for key, value in
|
|
102
|
+
for key, value in extraArgs do
|
|
90
103
|
formattedArgs[key] = value
|
|
91
104
|
end
|
|
92
105
|
end
|
|
@@ -103,20 +116,29 @@ end
|
|
|
103
116
|
@param extraArgs table?
|
|
104
117
|
@return Observable<string>
|
|
105
118
|
]=]
|
|
106
|
-
function LocalizedTextUtils.observeFormatByKeyRecursive(
|
|
119
|
+
function LocalizedTextUtils.observeFormatByKeyRecursive(
|
|
120
|
+
translator,
|
|
121
|
+
translationKey: string,
|
|
122
|
+
translationArgs: TranslationArgs,
|
|
123
|
+
extraArgs
|
|
124
|
+
)
|
|
107
125
|
assert(translator, "Bad translator")
|
|
108
126
|
assert(type(translationKey) == "string", "Bad translationKey")
|
|
109
127
|
assert(type(translationArgs) == "table" or translationArgs == nil, "Bad translationArgs")
|
|
110
128
|
|
|
111
129
|
local observableFormattedArgs = {}
|
|
112
130
|
if translationArgs then
|
|
113
|
-
for name, value in
|
|
131
|
+
for name, value in translationArgs do
|
|
114
132
|
if type(value) == "table" then
|
|
115
133
|
assert(value.translationKey, "Table, but no translationKey")
|
|
116
134
|
|
|
117
135
|
if value.translationArgs then
|
|
118
|
-
observableFormattedArgs[name] = LocalizedTextUtils
|
|
119
|
-
|
|
136
|
+
observableFormattedArgs[name] = LocalizedTextUtils.observeFormatByKeyRecursive(
|
|
137
|
+
translator,
|
|
138
|
+
value.translationKey,
|
|
139
|
+
value.translationArgs,
|
|
140
|
+
extraArgs
|
|
141
|
+
)
|
|
120
142
|
else
|
|
121
143
|
observableFormattedArgs[name] = translator:ObserveFormatByKey(value.translationKey)
|
|
122
144
|
end
|
|
@@ -127,7 +149,7 @@ function LocalizedTextUtils.observeFormatByKeyRecursive(translator, translationK
|
|
|
127
149
|
end
|
|
128
150
|
|
|
129
151
|
if extraArgs then
|
|
130
|
-
for key, value in
|
|
152
|
+
for key, value in extraArgs do
|
|
131
153
|
observableFormattedArgs[key] = value
|
|
132
154
|
end
|
|
133
155
|
end
|
|
@@ -143,7 +165,7 @@ end
|
|
|
143
165
|
@param extraArgs table?
|
|
144
166
|
@return Observable<string>
|
|
145
167
|
]=]
|
|
146
|
-
function LocalizedTextUtils.observeLocalizedTextToString(translator, localizedText, extraArgs)
|
|
168
|
+
function LocalizedTextUtils.observeLocalizedTextToString(translator, localizedText: LocalizedTextData, extraArgs)
|
|
147
169
|
assert(translator, "Bad translator")
|
|
148
170
|
assert(LocalizedTextUtils.isLocalizedText(localizedText), "No localizedText")
|
|
149
171
|
|
|
@@ -151,7 +173,8 @@ function LocalizedTextUtils.observeLocalizedTextToString(translator, localizedTe
|
|
|
151
173
|
translator,
|
|
152
174
|
localizedText.translationKey,
|
|
153
175
|
localizedText.translationArgs,
|
|
154
|
-
extraArgs
|
|
176
|
+
extraArgs
|
|
177
|
+
)
|
|
155
178
|
end
|
|
156
179
|
|
|
157
180
|
--[=[
|
|
@@ -166,7 +189,7 @@ end
|
|
|
166
189
|
@param extraArgs table?
|
|
167
190
|
@return string
|
|
168
191
|
]=]
|
|
169
|
-
function LocalizedTextUtils.localizedTextToString(translator, localizedText, extraArgs)
|
|
192
|
+
function LocalizedTextUtils.localizedTextToString(translator, localizedText: LocalizedTextData, extraArgs)
|
|
170
193
|
assert(translator, "Bad translator")
|
|
171
194
|
assert(LocalizedTextUtils.isLocalizedText(localizedText), "No localizedText")
|
|
172
195
|
|
|
@@ -174,7 +197,8 @@ function LocalizedTextUtils.localizedTextToString(translator, localizedText, ext
|
|
|
174
197
|
translator,
|
|
175
198
|
localizedText.translationKey,
|
|
176
199
|
localizedText.translationArgs,
|
|
177
|
-
extraArgs
|
|
200
|
+
extraArgs
|
|
201
|
+
)
|
|
178
202
|
end
|
|
179
203
|
|
|
180
204
|
--[=[
|
|
@@ -182,7 +206,7 @@ end
|
|
|
182
206
|
@param text string
|
|
183
207
|
@return LocalizedTextData?
|
|
184
208
|
]=]
|
|
185
|
-
function LocalizedTextUtils.fromJSON(text)
|
|
209
|
+
function LocalizedTextUtils.fromJSON(text: string): LocalizedTextData?
|
|
186
210
|
assert(type(text) == "string", "Bad text")
|
|
187
211
|
|
|
188
212
|
local decoded
|
|
@@ -201,7 +225,7 @@ end
|
|
|
201
225
|
@param localizedText LocalizedTextData
|
|
202
226
|
@return string?
|
|
203
227
|
]=]
|
|
204
|
-
function LocalizedTextUtils.toJSON(localizedText)
|
|
228
|
+
function LocalizedTextUtils.toJSON(localizedText: LocalizedTextData): string
|
|
205
229
|
assert(LocalizedTextUtils.isLocalizedText(localizedText), "Bad localizedText")
|
|
206
230
|
|
|
207
231
|
local localized = HttpService:JSONEncode(localizedText)
|
|
@@ -214,9 +238,13 @@ end
|
|
|
214
238
|
@param attributeName string
|
|
215
239
|
@param translationKey string
|
|
216
240
|
@param translationArgs TranslationArgs
|
|
217
|
-
@return LocalizedTextData
|
|
218
241
|
]=]
|
|
219
|
-
function LocalizedTextUtils.setFromAttribute(
|
|
242
|
+
function LocalizedTextUtils.setFromAttribute(
|
|
243
|
+
obj: Instance,
|
|
244
|
+
attributeName: string,
|
|
245
|
+
translationKey: string,
|
|
246
|
+
translationArgs: TranslationArgs
|
|
247
|
+
)
|
|
220
248
|
assert(typeof(obj) == "Instance", "Bad obj")
|
|
221
249
|
assert(type(attributeName) == "string", "Bad attributeName")
|
|
222
250
|
|
|
@@ -230,7 +258,7 @@ end
|
|
|
230
258
|
@param attributeName string
|
|
231
259
|
@return LocalizedTextData
|
|
232
260
|
]=]
|
|
233
|
-
function LocalizedTextUtils.getFromAttribute(obj, attributeName)
|
|
261
|
+
function LocalizedTextUtils.getFromAttribute(obj: Instance, attributeName: string): LocalizedTextData?
|
|
234
262
|
assert(typeof(obj) == "Instance", "Bad obj")
|
|
235
263
|
assert(type(attributeName) == "string", "Bad attributeName")
|
|
236
264
|
|
|
@@ -250,7 +278,12 @@ end
|
|
|
250
278
|
@param extraArgs table?
|
|
251
279
|
@return string?
|
|
252
280
|
]=]
|
|
253
|
-
function LocalizedTextUtils.getTranslationFromAttribute(
|
|
281
|
+
function LocalizedTextUtils.getTranslationFromAttribute(
|
|
282
|
+
translator,
|
|
283
|
+
obj: Instance,
|
|
284
|
+
attributeName: string,
|
|
285
|
+
extraArgs
|
|
286
|
+
): string?
|
|
254
287
|
assert(translator, "Bad translator")
|
|
255
288
|
assert(typeof(obj) == "Instance", "Bad obj")
|
|
256
289
|
assert(type(attributeName) == "string", "Bad attributeName")
|
|
@@ -270,7 +303,12 @@ end
|
|
|
270
303
|
@param defaultTranslationKey string
|
|
271
304
|
@param defaultTranslationArgs table?
|
|
272
305
|
]=]
|
|
273
|
-
function LocalizedTextUtils.initializeAttribute(
|
|
306
|
+
function LocalizedTextUtils.initializeAttribute(
|
|
307
|
+
obj,
|
|
308
|
+
attributeName: string,
|
|
309
|
+
defaultTranslationKey,
|
|
310
|
+
defaultTranslationArgs
|
|
311
|
+
)
|
|
274
312
|
assert(typeof(obj) == "Instance", "Bad obj")
|
|
275
313
|
assert(type(attributeName) == "string", "Bad attributeName")
|
|
276
314
|
assert(type(defaultTranslationKey) == "string", "Bad defaultTranslationKey")
|
|
@@ -291,30 +329,30 @@ end
|
|
|
291
329
|
@param extraArgs table?
|
|
292
330
|
@return Observable<string?>
|
|
293
331
|
]=]
|
|
294
|
-
function LocalizedTextUtils.observeTranslation(translator, obj, attributeName, extraArgs)
|
|
332
|
+
function LocalizedTextUtils.observeTranslation(translator, obj: Instance, attributeName: string, extraArgs)
|
|
295
333
|
assert(translator, "Bad translator")
|
|
296
334
|
assert(typeof(obj) == "Instance", "Bad obj")
|
|
297
335
|
assert(type(attributeName) == "string", "Bad attributeName")
|
|
298
336
|
|
|
299
|
-
return RxAttributeUtils.observeAttribute(obj, attributeName, nil)
|
|
300
|
-
:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
else
|
|
311
|
-
return Rx.of(nil)
|
|
312
|
-
end
|
|
337
|
+
return RxAttributeUtils.observeAttribute(obj, attributeName, nil):Pipe({
|
|
338
|
+
Rx.switchMap(function(encodedText): any
|
|
339
|
+
if type(encodedText) == "string" then
|
|
340
|
+
local localizedText = LocalizedTextUtils.fromJSON(encodedText)
|
|
341
|
+
if localizedText then
|
|
342
|
+
return LocalizedTextUtils.observeFormatByKeyRecursive(
|
|
343
|
+
translator,
|
|
344
|
+
localizedText.translationKey,
|
|
345
|
+
localizedText.translationArgs,
|
|
346
|
+
extraArgs
|
|
347
|
+
)
|
|
313
348
|
else
|
|
314
349
|
return Rx.of(nil)
|
|
315
350
|
end
|
|
316
|
-
|
|
317
|
-
|
|
351
|
+
else
|
|
352
|
+
return Rx.of(nil)
|
|
353
|
+
end
|
|
354
|
+
end) :: any,
|
|
355
|
+
}) :: any
|
|
318
356
|
end
|
|
319
357
|
|
|
320
358
|
return LocalizedTextUtils
|