@quenty/clienttranslator 9.1.1 → 9.2.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
+ # [9.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/clienttranslator@9.1.1...@quenty/clienttranslator@9.2.0) (2023-12-14)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add support for roundingbehaviortypes.NONE and ([6869d9e](https://github.com/Quenty/NevermoreEngine/commit/6869d9e5b3a726fa3e15e6dbbfeedebdfcc71a3d))
12
+ * Handle studio test mode localization numbers ([a30226d](https://github.com/Quenty/NevermoreEngine/commit/a30226d1d64cb2df89450d3d33b81d15192e61ff))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [9.1.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/clienttranslator@9.1.0...@quenty/clienttranslator@9.1.1) (2023-10-28)
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": "9.1.1",
3
+ "version": "9.2.0",
4
4
  "description": "Gets local translator for player",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -25,18 +25,18 @@
25
25
  "Quenty"
26
26
  ],
27
27
  "dependencies": {
28
- "@quenty/blend": "^7.1.1",
29
- "@quenty/instanceutils": "^8.1.1",
30
- "@quenty/loader": "^7.0.0",
28
+ "@quenty/blend": "^7.2.0",
29
+ "@quenty/instanceutils": "^8.2.0",
30
+ "@quenty/loader": "^7.1.0",
31
31
  "@quenty/maid": "^2.6.0",
32
- "@quenty/promise": "^7.0.0",
32
+ "@quenty/promise": "^7.1.0",
33
33
  "@quenty/pseudolocalize": "^3.2.0",
34
- "@quenty/rx": "^8.1.1",
34
+ "@quenty/rx": "^8.2.0",
35
35
  "@quenty/string": "^3.1.0",
36
- "@quenty/table": "^3.3.0"
36
+ "@quenty/table": "^3.4.0"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "440aca7ce2b50b74317ee05fdc0b8d1e58001af3"
41
+ "gitHead": "2c2dbbc0cb2fbb46b4f3270c559c63890fe18b26"
42
42
  }
@@ -180,6 +180,7 @@ localeInfos["tr-tr"] = {
180
180
  }
181
181
 
182
182
  -- Aliases for languages that use the same mappings.
183
+ localeInfos["en"] = localeInfos["en-us"]
183
184
  localeInfos["en-gb"] = localeInfos["en-us"]
184
185
  localeInfos["es-mx"] = localeInfos["es-es"]
185
186
 
@@ -201,7 +202,7 @@ local function roundToSignificantDigits(number, significantDigits, roundingBehav
201
202
  local offset = findDecimalOffset(number)
202
203
  local multiplier = 10^(significantDigits + offset)
203
204
  local significand
204
- if roundingBehaviourType == RoundingBehaviourTypes.Truncate then
205
+ if roundingBehaviourType == RoundingBehaviourTypes.TRUNCATE then
205
206
  significand = math.modf(number * multiplier)
206
207
  else
207
208
  significand = math.floor(number * multiplier + 0.5)
@@ -228,7 +229,7 @@ local function findDenominationEntry(localeInfo, number, roundingBehaviourType)
228
229
  for i = #localeInfo, 2, -1 do
229
230
  local entry = localeInfo[i]
230
231
  local baseValue
231
- if roundingBehaviourType == RoundingBehaviourTypes.Truncate then
232
+ if roundingBehaviourType == RoundingBehaviourTypes.TRUNCATE then
232
233
  baseValue = entry[1]
233
234
  else
234
235
  baseValue = entry[1] - (localeInfo[i - 1][1]) / 2
@@ -260,13 +261,31 @@ function NumberLocalizationUtils.localize(number, locale)
260
261
  return number
261
262
  end
262
263
 
264
+ --[=[
265
+ Abbreviates the number to a truncated amount in a localized way.
266
+
267
+ ```lua
268
+ print(NumberLocalizationUtils.abbreviate(2500, "en-us", RoundingBehaviourTypes.ROUND_TO_CLOSEST, 3)) --> 2.5k
269
+ ```
270
+
271
+ @param number number
272
+ @param locale string
273
+ @param roundingBehaviourType RoundingBehaviourType?
274
+ @param numSignificantDigits number?
275
+ ]=]
263
276
  function NumberLocalizationUtils.abbreviate(number, locale, roundingBehaviourType, numSignificantDigits)
277
+ assert(type(number) == "number", "Bad number")
278
+
279
+ if roundingBehaviourType == RoundingBehaviourTypes.NONE then
280
+ return NumberLocalizationUtils.localize(number, locale)
281
+ end
282
+
264
283
  if number == 0 then
265
284
  return "0"
266
285
  end
267
286
 
268
287
  if roundingBehaviourType == nil then
269
- roundingBehaviourType = RoundingBehaviourTypes.RoundToClosest
288
+ roundingBehaviourType = RoundingBehaviourTypes.ROUND_TO_CLOSEST
270
289
  end
271
290
 
272
291
  if numSignificantDigits == nil then
@@ -290,11 +309,14 @@ function NumberLocalizationUtils.abbreviate(number, locale, roundingBehaviourTyp
290
309
 
291
310
  -- trim to 1 decimal point
292
311
  local trimmedQuotient
293
- if roundingBehaviourType == RoundingBehaviourTypes.Truncate then
312
+ if roundingBehaviourType == RoundingBehaviourTypes.TRUNCATE then
294
313
  trimmedQuotient = math.modf(significantQuotient * 10) / 10
295
- else
314
+ elseif roundingBehaviourType == RoundingBehaviourTypes.ROUND_TO_CLOSEST then
296
315
  trimmedQuotient = math.floor(significantQuotient * 10 + 0.5) / 10
316
+ else
317
+ error(string.format("[NumberLocalizationUtils.abbreviate] - Unknown roundingBehaviourType %q", tostring(roundingBehaviourType)))
297
318
  end
319
+
298
320
  local trimmedQuotientString = tostring(trimmedQuotient)
299
321
 
300
322
  -- Split the string into integer and fraction parts
@@ -1,7 +1,7 @@
1
1
  local require = require(script.Parent.loader).load(script)
2
2
 
3
3
  local NumberLocalizationUtils = require("NumberLocalizationUtils")
4
- local RoundingBehaviour = require("RoundingBehaviourTypes")
4
+ local RoundingBehaviourTypes = require("RoundingBehaviourTypes")
5
5
 
6
6
  return function()
7
7
 
@@ -68,7 +68,7 @@ return function()
68
68
  end)
69
69
 
70
70
  describe("NumberLocalizationUtils.abbreviate", function()
71
- it("should round towards zero when using RoundingBehaviour.Truncate", function()
71
+ it("should round towards zero when using RoundingBehaviourTypes.Truncate", function()
72
72
  local roundToZeroMap = {
73
73
  [0] = "0",
74
74
  [1] = "1",
@@ -103,7 +103,7 @@ return function()
103
103
  }
104
104
 
105
105
  for input, output in pairs(roundToZeroMap) do
106
- expect(NumberLocalizationUtils.abbreviate(input, "en-us", RoundingBehaviour.Truncate)).to.equal(output)
106
+ expect(NumberLocalizationUtils.abbreviate(input, "en-us", RoundingBehaviourTypes.TRUNCATE)).to.equal(output)
107
107
  end
108
108
  end)
109
109
  end)
@@ -7,6 +7,7 @@ local require = require(script.Parent.loader).load(script)
7
7
  local Table = require("Table")
8
8
 
9
9
  return Table.readonly({
10
- RoundToClosest = "roundToClosest";
11
- Truncate = "truncate";
10
+ ROUND_TO_CLOSEST = "roundToClosest";
11
+ TRUNCATE = "truncate";
12
+ NONE = "None"
12
13
  })