@quenty/clienttranslator 4.4.1 → 4.5.0-canary.241.a4e8214.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 CHANGED
@@ -3,6 +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
+ # [4.5.0-canary.241.a4e8214.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/clienttranslator@4.4.1...@quenty/clienttranslator@4.5.0-canary.241.a4e8214.0) (2022-01-03)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add JSONTranslator:ObserveFormatByKey(key, argData) ([60c9ece](https://github.com/Quenty/NevermoreEngine/commit/60c9ecec2679f4392f1ee8c4f3008dfe9ec68ffa))
12
+ * Suppress localization warnings when game is not published ([f0961eb](https://github.com/Quenty/NevermoreEngine/commit/f0961ebbc2359a8e7f89576664c0fb80ca9bfdae))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [4.4.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/clienttranslator@4.4.0...@quenty/clienttranslator@4.4.1) (2021-12-30)
7
19
 
8
20
  **Note:** Version bump only for package @quenty/clienttranslator
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/clienttranslator",
3
- "version": "4.4.1",
3
+ "version": "4.5.0-canary.241.a4e8214.0",
4
4
  "description": "Gets local translator for player",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,12 +25,15 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/loader": "^3.1.2",
29
- "@quenty/promise": "^3.3.1",
30
- "@quenty/pseudolocalize": "^2.0.1"
28
+ "@quenty/blend": "2.1.0-canary.241.a4e8214.0",
29
+ "@quenty/loader": "3.2.0-canary.241.a4e8214.0",
30
+ "@quenty/maid": "2.0.2",
31
+ "@quenty/promise": "3.4.0-canary.241.a4e8214.0",
32
+ "@quenty/pseudolocalize": "2.0.1",
33
+ "@quenty/rx": "3.6.0-canary.241.a4e8214.0"
31
34
  },
32
35
  "publishConfig": {
33
36
  "access": "public"
34
37
  },
35
- "gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
38
+ "gitHead": "a4e821471f35998d63f38a4f4a578e07b4e79035"
36
39
  }
@@ -13,6 +13,10 @@ local JsonToLocalizationTable = require("JsonToLocalizationTable")
13
13
  local PseudoLocalize = require("PseudoLocalize")
14
14
  local LocalizationServiceUtils = require("LocalizationServiceUtils")
15
15
  local Promise = require("Promise")
16
+ local Observable = require("Observable")
17
+ local Maid = require("Maid")
18
+ local Blend = require("Blend")
19
+ local Rx = require("Rx")
16
20
 
17
21
  local JSONTranslator = {}
18
22
  JSONTranslator.ClassName = "JSONTranslator"
@@ -98,6 +102,45 @@ function JSONTranslator:PromiseFormatByKey(key, args)
98
102
  end)
99
103
  end
100
104
 
105
+ --[=[
106
+ Observes the translated value
107
+ @param key string
108
+ @param argData table? -- May have observables (or convertable to observables) in it.
109
+ @return Observable<string>
110
+ ]=]
111
+ function JSONTranslator:ObserveFormatByKey(key, argData)
112
+ assert(self ~= JSONTranslator, "Construct a new version of this class to use it")
113
+ assert(type(key) == "string", "Key must be a string")
114
+
115
+ local argObservable
116
+ if argData then
117
+ local args = {}
118
+ for argKey, value in pairs(argData) do
119
+ args[argKey] = Blend.toPropertyObservable(value) or Rx.of(value)
120
+ end
121
+
122
+ argObservable = Rx.combineLatest(args)
123
+ else
124
+ argObservable = nil
125
+ end
126
+
127
+ return Observable.new(function(sub)
128
+ local maid = Maid.new()
129
+
130
+ maid:GivePromise(self._promiseTranslator:Then(function()
131
+ if argObservable then
132
+ maid:GiveTask(argObservable:Subscribe(function(args)
133
+ sub:Fire(self:FormatByKey(key, args))
134
+ end))
135
+ else
136
+ sub:Fire(self:FormatByKey(key, nil))
137
+ end
138
+ end))
139
+
140
+ return maid
141
+ end)
142
+ end
143
+
101
144
  --[=[
102
145
  Formats or errors if the cloud translations are not loaded.
103
146
  @param key string
@@ -8,6 +8,7 @@ local LocalizationService = game:GetService("LocalizationService")
8
8
  local RunService = game:GetService("RunService")
9
9
 
10
10
  local Promise = require("Promise")
11
+ local ERROR_PUBLISH_REQUIRED = "Publishing the game is required to use GetTranslatorForPlayerAsync API."
11
12
 
12
13
  local LocalizationServiceUtils = {}
13
14
 
@@ -49,7 +50,9 @@ function LocalizationServiceUtils.promiseTranslator(player)
49
50
  end)
50
51
 
51
52
  return asyncTranslatorPromise:Catch(function(err)
52
- warn(("[LocalizationServiceUtils.promiseTranslator] - %s"):format(tostring(err)))
53
+ if err ~= ERROR_PUBLISH_REQUIRED then
54
+ warn(("[LocalizationServiceUtils.promiseTranslator] - %s"):format(tostring(err)))
55
+ end
53
56
 
54
57
  -- Fallback to just local stuff
55
58
  local translator = LocalizationService:GetTranslatorForPlayer(player)