@quenty/localizedtextutils 2.2.2-canary.4c04014.0 → 3.0.0
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 +12 -1
- package/package.json +5 -5
- package/src/Shared/LocalizedTextUtils.lua +63 -16
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,18 @@
|
|
|
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
|
-
|
|
6
|
+
# [3.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/localizedtextutils@2.3.0...@quenty/localizedtextutils@3.0.0) (2022-03-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add LocalizedTextUtils.observeFormatByKeyRecursive and ensure that observation can occur of observable translatable objects ([feca173](https://github.com/Quenty/NevermoreEngine/commit/feca17331b27013552c095f830387c789a954f89))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [2.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/localizedtextutils@2.2.1...@quenty/localizedtextutils@2.3.0) (2022-01-17)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/localizedtextutils
|
|
9
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/localizedtextutils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Localized text utils which changes translationKey structures to shared locations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@quenty/attributeutils": "
|
|
32
|
-
"@quenty/loader": "
|
|
33
|
-
"@quenty/rx": "
|
|
31
|
+
"@quenty/attributeutils": "^5.0.0",
|
|
32
|
+
"@quenty/loader": "^4.0.0",
|
|
33
|
+
"@quenty/rx": "^4.0.0"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "dd428cab58282c975a4c082957dc8f58e3186905"
|
|
36
36
|
}
|
|
@@ -58,28 +58,30 @@ end
|
|
|
58
58
|
Recursively formats the translated text.
|
|
59
59
|
@param translator Translator | JSONTranslator
|
|
60
60
|
@param translationKey string
|
|
61
|
-
@param translationArgs TranslationArgs
|
|
61
|
+
@param translationArgs TranslationArgs?
|
|
62
62
|
@param extraArgs table?
|
|
63
63
|
@return string
|
|
64
64
|
]=]
|
|
65
65
|
function LocalizedTextUtils.formatByKeyRecursive(translator, translationKey, translationArgs, extraArgs)
|
|
66
66
|
assert(translator, "Bad translator")
|
|
67
67
|
assert(type(translationKey) == "string", "Bad translationKey")
|
|
68
|
-
assert(type(translationArgs) == "table", "Bad translationArgs")
|
|
68
|
+
assert(type(translationArgs) == "table" or translationArgs == nil, "Bad translationArgs")
|
|
69
69
|
|
|
70
70
|
local formattedArgs = {}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
if translationArgs then
|
|
72
|
+
for name, value in pairs(translationArgs) do
|
|
73
|
+
if type(value) == "table" then
|
|
74
|
+
assert(value.translationKey, "Table, but no translationKey")
|
|
75
|
+
|
|
76
|
+
if value.translationArgs then
|
|
77
|
+
formattedArgs[name] = LocalizedTextUtils
|
|
78
|
+
.formatByKeyRecursive(translator, value.translationKey, value.translationArgs, extraArgs)
|
|
79
|
+
else
|
|
80
|
+
formattedArgs[name] = translator:FormatByKey(value.translationKey)
|
|
81
|
+
end
|
|
78
82
|
else
|
|
79
|
-
formattedArgs[name] =
|
|
83
|
+
formattedArgs[name] = value
|
|
80
84
|
end
|
|
81
|
-
else
|
|
82
|
-
formattedArgs[name] = value
|
|
83
85
|
end
|
|
84
86
|
end
|
|
85
87
|
|
|
@@ -92,6 +94,47 @@ function LocalizedTextUtils.formatByKeyRecursive(translator, translationKey, tra
|
|
|
92
94
|
return translator:FormatByKey(translationKey, formattedArgs)
|
|
93
95
|
end
|
|
94
96
|
|
|
97
|
+
--[=[
|
|
98
|
+
Observes the recursively formatted translated text.
|
|
99
|
+
|
|
100
|
+
@param translator Translator | JSONTranslator
|
|
101
|
+
@param translationKey string
|
|
102
|
+
@param translationArgs TranslationArgs?
|
|
103
|
+
@param extraArgs table?
|
|
104
|
+
@return Observable<string>
|
|
105
|
+
]=]
|
|
106
|
+
function LocalizedTextUtils.observeFormatByKeyRecursive(translator, translationKey, translationArgs, extraArgs)
|
|
107
|
+
assert(translator, "Bad translator")
|
|
108
|
+
assert(type(translationKey) == "string", "Bad translationKey")
|
|
109
|
+
assert(type(translationArgs) == "table" or translationArgs == nil, "Bad translationArgs")
|
|
110
|
+
|
|
111
|
+
local observableFormattedArgs = {}
|
|
112
|
+
if translationArgs then
|
|
113
|
+
for name, value in pairs(translationArgs) do
|
|
114
|
+
if type(value) == "table" then
|
|
115
|
+
assert(value.translationKey, "Table, but no translationKey")
|
|
116
|
+
|
|
117
|
+
if value.translationArgs then
|
|
118
|
+
observableFormattedArgs[name] = LocalizedTextUtils
|
|
119
|
+
.observeFormatByKeyRecursive(translator, value.translationKey, value.translationArgs, extraArgs)
|
|
120
|
+
else
|
|
121
|
+
observableFormattedArgs[name] = translator:ObserveFormatByKey(value.translationKey)
|
|
122
|
+
end
|
|
123
|
+
else
|
|
124
|
+
observableFormattedArgs[name] = value
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
if extraArgs then
|
|
130
|
+
for key, value in pairs(extraArgs) do
|
|
131
|
+
observableFormattedArgs[key] = value
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
return translator:ObserveFormatByKey(translationKey, observableFormattedArgs)
|
|
136
|
+
end
|
|
137
|
+
|
|
95
138
|
--[=[
|
|
96
139
|
Recursively formats the translated text
|
|
97
140
|
@param translator Translator | JSONTranslator
|
|
@@ -231,16 +274,20 @@ function LocalizedTextUtils.observeTranslation(translator, obj, attributeName, e
|
|
|
231
274
|
|
|
232
275
|
return RxAttributeUtils.observeAttribute(obj, attributeName, nil)
|
|
233
276
|
:Pipe({
|
|
234
|
-
Rx.
|
|
277
|
+
Rx.switchMap(function(encodedText)
|
|
235
278
|
if type(encodedText) == "string" then
|
|
236
279
|
local localizedText = LocalizedTextUtils.fromJSON(encodedText)
|
|
237
280
|
if localizedText then
|
|
238
|
-
return LocalizedTextUtils.
|
|
281
|
+
return LocalizedTextUtils.observeFormatByKeyRecursive(
|
|
282
|
+
translator,
|
|
283
|
+
localizedText.translationKey,
|
|
284
|
+
localizedText.translationArgs,
|
|
285
|
+
extraArgs)
|
|
239
286
|
else
|
|
240
|
-
return nil
|
|
287
|
+
return Rx.of(nil)
|
|
241
288
|
end
|
|
242
289
|
else
|
|
243
|
-
return nil
|
|
290
|
+
return Rx.of(nil)
|
|
244
291
|
end
|
|
245
292
|
end);
|
|
246
293
|
})
|