Working on translation context
This commit is contained in:
69
scripts/TransContext.gd
Normal file
69
scripts/TransContext.gd
Normal file
@@ -0,0 +1,69 @@
|
||||
class_name TransContext
|
||||
|
||||
var default:String = "title"
|
||||
var pluralContext:String = "count"
|
||||
var trans:Dictionary[String, String] = {}
|
||||
var transPlural:Dictionary[String, String] = {}
|
||||
var transBool:Dictionary[String, bool] = {}
|
||||
var transInteger:Dictionary[String, int] = {}
|
||||
var transFloat:Dictionary[String, float] = {}
|
||||
var subContexts:Dictionary[String, TransContext] = {}
|
||||
|
||||
func setDefault(key:String) -> void:
|
||||
default = key
|
||||
|
||||
func setPluralContext(key:String) -> void:
|
||||
pluralContext = key
|
||||
|
||||
func addContext(key:String, ctx:TransContext) -> void:
|
||||
if subContexts.has(key):
|
||||
assert(false, "Context already exists: " + key)
|
||||
subContexts[key] = ctx
|
||||
|
||||
func addTrans(key:String, transl:String) -> void:
|
||||
if trans.has(key):
|
||||
assert(false, "Trans String already exists: " + key)
|
||||
trans[key] = transl
|
||||
|
||||
func addTransPlural(key:String, transl:String, suffix:String = "_plural") -> void:
|
||||
if transPlural.has(key + suffix) || transPlural.has(key):
|
||||
assert(false, "Trans Plural String already exists: " + key)
|
||||
trans[key] = transl
|
||||
transPlural[key] = transl + suffix
|
||||
|
||||
func addBool(key:String, value:bool) -> void:
|
||||
if transBool.has(key):
|
||||
assert(false, "Trans Bool String already exists: " + key)
|
||||
transBool[key] = value
|
||||
|
||||
func addInteger(key:String, value:int) -> void:
|
||||
if transInteger.has(key):
|
||||
assert(false, "Trans Integer String already exists: " + key)
|
||||
transInteger[key] = value
|
||||
|
||||
func addFloat(key:String, value:float) -> void:
|
||||
if transFloat.has(key):
|
||||
assert(false, "Trans Float String already exists: " + key)
|
||||
transFloat[key] = value
|
||||
|
||||
# func build(parentContext:TransContext = null) -> Dictionary[String, String]:
|
||||
# var dict:Dictionary[String, String] = {}
|
||||
|
||||
# for transKey in trans.keys():
|
||||
# dict[transKey] = trans[transKey]
|
||||
|
||||
# for transKey in transPlural.keys():
|
||||
# dict[transKey] = transPlural[transKey]
|
||||
|
||||
# for transKey in transBool.keys():
|
||||
# dict[transKey] = str(transBool[transKey])
|
||||
|
||||
# for transKey in transInteger.keys():
|
||||
# dict[transKey] = str(transInteger[transKey])
|
||||
|
||||
# for transKey in transFloat.keys():
|
||||
# dict[transKey] = str(transFloat[transKey])
|
||||
|
||||
# return dict
|
||||
|
||||
func translate(key:String) -> String:
|
Reference in New Issue
Block a user