mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
* Move grammar parsers to entity classes * Fix includes * Fix Entity5 test * Small detail * Fix unknown keys entities * Persistent grammar objects * Fix grammar * Grammar from variable
55 lines
1.6 KiB
JavaScript
Executable File
55 lines
1.6 KiB
JavaScript
Executable File
import Grammar from "../serialization/Grammar.js"
|
|
import IEntity from "./IEntity.js"
|
|
import Utility from "../Utility.js"
|
|
|
|
export default class LocalizedTextEntity extends IEntity {
|
|
|
|
static lookbehind = "NSLOCTEXT"
|
|
static attributes = {
|
|
...super.attributes,
|
|
namespace: {
|
|
default: "",
|
|
},
|
|
key: {
|
|
default: "",
|
|
},
|
|
value: {
|
|
default: "",
|
|
},
|
|
}
|
|
static {
|
|
this.cleanupAttributes(this.attributes)
|
|
}
|
|
static grammar = this.createGrammar()
|
|
|
|
static createGrammar() {
|
|
return Grammar.regexMap(
|
|
new RegExp(
|
|
String.raw`${this.lookbehind}\s*\(`
|
|
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*,`
|
|
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*,`
|
|
+ String.raw`\s*"(${Grammar.Regex.InsideString.source})"\s*`
|
|
+ String.raw`(?:,\s+)?`
|
|
+ String.raw`\)`,
|
|
"m"
|
|
),
|
|
matchResult => new this({
|
|
namespace: Utility.unescapeString(matchResult[1]),
|
|
key: Utility.unescapeString(matchResult[2]),
|
|
value: Utility.unescapeString(matchResult[3]),
|
|
})
|
|
)
|
|
}
|
|
|
|
constructor(values) {
|
|
super(values)
|
|
/** @type {String} */ this.namespace
|
|
/** @type {String} */ this.key
|
|
/** @type {String} */ this.value
|
|
}
|
|
|
|
toString() {
|
|
return Utility.capitalFirstLetter(this.value)
|
|
}
|
|
}
|