@quenty/localizedtextutils 2.0.0 → 2.0.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 +8 -0
- package/LICENSE.md +1 -1
- package/README.md +6 -16
- package/package.json +2 -2
- package/src/Shared/LocalizedTextUtils.lua +42 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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
|
+
## [2.0.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/localizedtextutils@2.0.0...@quenty/localizedtextutils@2.0.1) (2021-12-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/localizedtextutils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [2.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/localizedtextutils@1.2.0...@quenty/localizedtextutils@2.0.0) (2021-09-05)
|
|
7
15
|
|
|
8
16
|
|
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
## LocalizedTextUtils
|
|
2
2
|
<div align="center">
|
|
3
|
-
<a href="http://quenty.github.io/
|
|
4
|
-
<img src="https://
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
5
5
|
</a>
|
|
6
6
|
<a href="https://discord.gg/mhtGUS8">
|
|
7
|
-
<img src="https://img.shields.io/
|
|
7
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
8
8
|
</a>
|
|
9
9
|
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
10
10
|
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
|
@@ -13,19 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
Localized text utils which changes translationKey structures to shared locations
|
|
15
15
|
|
|
16
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/LocalizedTextUtils">View docs →</a></div>
|
|
17
|
+
|
|
16
18
|
## Installation
|
|
17
19
|
```
|
|
18
20
|
npm install @quenty/localizedtextutils --save
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
Usage is designed to be simple.
|
|
23
|
-
|
|
24
|
-
### `LocalizedTextUtils.create(translationKey, translationArgs)`
|
|
25
|
-
|
|
26
|
-
### `LocalizedTextUtils.isLocalizedText(data)`
|
|
27
|
-
|
|
28
|
-
### `LocalizedTextUtils.formatByKeyRecursive(translator, translationKey, translationArgs)`
|
|
29
|
-
|
|
30
|
-
### `LocalizedTextUtils.localizedTextToString(translator, localizedText)`
|
|
31
|
-
|
|
21
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/localizedtextutils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Localized text utils which changes translationKey structures to shared locations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "d146c77d0a8e452824de0ab0b4b03ba0370bcc1b"
|
|
31
31
|
}
|
|
@@ -1,8 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Localized text utils which changes translationKey structures to shared locations
|
|
3
|
+
@class LocalizedTextUtils
|
|
4
|
+
]=]
|
|
3
5
|
|
|
4
6
|
local LocalizedTextUtils = {}
|
|
5
7
|
|
|
8
|
+
--[=[
|
|
9
|
+
Valid translation args
|
|
10
|
+
@type TranslationArgs { [string]: LocalizedTextData | number | string }
|
|
11
|
+
@within LocalizedTextUtils
|
|
12
|
+
]=]
|
|
13
|
+
|
|
14
|
+
--[=[
|
|
15
|
+
Valid localized text data
|
|
16
|
+
@interface LocalizedTextData
|
|
17
|
+
.translationKey string
|
|
18
|
+
.translationArgs TranslationArgs
|
|
19
|
+
@within LocalizedTextUtils
|
|
20
|
+
]=]
|
|
21
|
+
|
|
22
|
+
--[=[
|
|
23
|
+
Creates a new localizedtextdata
|
|
24
|
+
@param translationKey string
|
|
25
|
+
@param translationArgs TranslationArgs
|
|
26
|
+
@return LocalizedTextData
|
|
27
|
+
]=]
|
|
6
28
|
function LocalizedTextUtils.create(translationKey, translationArgs)
|
|
7
29
|
assert(type(translationKey) == "string", "Bad translationKey")
|
|
8
30
|
assert(type(translationArgs) == "table" or translationArgs == nil, "Bad translationArgs")
|
|
@@ -13,6 +35,11 @@ function LocalizedTextUtils.create(translationKey, translationArgs)
|
|
|
13
35
|
}
|
|
14
36
|
end
|
|
15
37
|
|
|
38
|
+
--[=[
|
|
39
|
+
Returns whether the given argument is localized text
|
|
40
|
+
@param data any
|
|
41
|
+
@return boolean
|
|
42
|
+
]=]
|
|
16
43
|
function LocalizedTextUtils.isLocalizedText(data)
|
|
17
44
|
return type(data) == "table"
|
|
18
45
|
and type(data.translationKey) == "string"
|
|
@@ -20,6 +47,13 @@ function LocalizedTextUtils.isLocalizedText(data)
|
|
|
20
47
|
or data.translationArgs == nil)
|
|
21
48
|
end
|
|
22
49
|
|
|
50
|
+
--[=[
|
|
51
|
+
Recursively formats the translated text
|
|
52
|
+
@param translator Translator | JSONTranslator
|
|
53
|
+
@param translationKey string
|
|
54
|
+
@param translationArgs TranslationArgs
|
|
55
|
+
@return string
|
|
56
|
+
]=]
|
|
23
57
|
function LocalizedTextUtils.formatByKeyRecursive(translator, translationKey, translationArgs)
|
|
24
58
|
assert(translator, "Bad translator")
|
|
25
59
|
assert(translationKey, "Bad translationKey")
|
|
@@ -44,6 +78,12 @@ function LocalizedTextUtils.formatByKeyRecursive(translator, translationKey, tra
|
|
|
44
78
|
return translator:FormatByKey(translationKey, formattedArgs)
|
|
45
79
|
end
|
|
46
80
|
|
|
81
|
+
--[=[
|
|
82
|
+
Recursively formats the translated text
|
|
83
|
+
@param translator Translator | JSONTranslator
|
|
84
|
+
@param localizedText LocalizedTextData
|
|
85
|
+
@return string
|
|
86
|
+
]=]
|
|
47
87
|
function LocalizedTextUtils.localizedTextToString(translator, localizedText)
|
|
48
88
|
assert(translator, "Bad translator")
|
|
49
89
|
assert(localizedText, "No localizedText")
|