Changed all translation to use new TransContext
This commit is contained in:
@@ -50,13 +50,13 @@ msgstr "Debug Battle"
|
|||||||
#
|
#
|
||||||
msgid "event.get_item.found"
|
msgid "event.get_item.found"
|
||||||
msgid_plural "event.get_item.found_plural"
|
msgid_plural "event.get_item.found_plural"
|
||||||
msgstr[0] "Found {item}."
|
msgstr[0] "Found {item.title}."
|
||||||
msgstr[1] "Found {quantity} {item}."
|
msgstr[1] "Found {quantity} {item.title}."
|
||||||
|
|
||||||
msgid "event.get_item.given"
|
msgid "event.get_item.given"
|
||||||
msgid_plural "event.get_item.given_plural"
|
msgid_plural "event.get_item.given_plural"
|
||||||
msgstr[0] "Received {item}."
|
msgstr[0] "Received {item.title}."
|
||||||
msgstr[1] "Received {quantity} {item}."
|
msgstr[1] "Received {quantity} {item.title}."
|
||||||
|
|
||||||
#
|
#
|
||||||
# QUESTS
|
# QUESTS
|
||||||
@@ -68,7 +68,7 @@ msgid "quest.test_quest.onion.title"
|
|||||||
msgstr "Scavenge Onions"
|
msgstr "Scavenge Onions"
|
||||||
|
|
||||||
msgid "quest.test_quest.onion.description"
|
msgid "quest.test_quest.onion.description"
|
||||||
msgstr "Find and collect {quantity} {item} and bring them back to {npc}."
|
msgstr "Find and collect {quantity} {item.title} and bring them back to {npc}."
|
||||||
|
|
||||||
#
|
#
|
||||||
# ITEMS
|
# ITEMS
|
||||||
@@ -123,4 +123,4 @@ msgstr ""
|
|||||||
|
|
||||||
# TEST
|
# TEST
|
||||||
msgid "test"
|
msgid "test"
|
||||||
msgstr "Test {title} String"
|
msgstr "Test {item.title} String"
|
@@ -18,7 +18,6 @@ metadata/_custom_type_script = "uid://dn0kxbe85n40f"
|
|||||||
script = ExtResource("3_l8p7p")
|
script = ExtResource("3_l8p7p")
|
||||||
title = "quest.test_quest.onion.title"
|
title = "quest.test_quest.onion.title"
|
||||||
description = "quest.test_quest.onion.description"
|
description = "quest.test_quest.onion.description"
|
||||||
objectiveType = null
|
|
||||||
itemType = 2
|
itemType = 2
|
||||||
quantity = 2
|
quantity = 2
|
||||||
metadata/_custom_type_script = "uid://de1ao4huhy0hm"
|
metadata/_custom_type_script = "uid://de1ao4huhy0hm"
|
||||||
|
@@ -7,13 +7,13 @@
|
|||||||
[sub_resource type="Resource" id="Resource_3dxl6"]
|
[sub_resource type="Resource" id="Resource_3dxl6"]
|
||||||
script = ExtResource("3_b8y03")
|
script = ExtResource("3_b8y03")
|
||||||
itemType = 3
|
itemType = 3
|
||||||
count = 1
|
quantity = 1
|
||||||
metadata/_custom_type_script = "uid://c26aptwsjs044"
|
metadata/_custom_type_script = "uid://c26aptwsjs044"
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_b8y03"]
|
[sub_resource type="Resource" id="Resource_b8y03"]
|
||||||
script = ExtResource("3_b8y03")
|
script = ExtResource("3_b8y03")
|
||||||
itemType = 4
|
itemType = 4
|
||||||
count = 1
|
quantity = 1
|
||||||
metadata/_custom_type_script = "uid://c26aptwsjs044"
|
metadata/_custom_type_script = "uid://c26aptwsjs044"
|
||||||
|
|
||||||
[node name="RecipeSystem" type="Node"]
|
[node name="RecipeSystem" type="Node"]
|
||||||
|
@@ -23,11 +23,11 @@ func start() -> void:
|
|||||||
textKey = "event.get_item.given"
|
textKey = "event.get_item.given"
|
||||||
_:
|
_:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
VN.getTextbox().setText(tr_n(textKey, textKey + "_plural", quantity).format({
|
var ctx = TransContext.new()
|
||||||
"item": ITEM.getItemName(itemType, quantity),
|
ctx.addInteger("quantity", quantity)
|
||||||
"quantity": quantity
|
ctx.addContext("item", ITEM.getItem(itemType).getTransContext())
|
||||||
}));
|
VN.getTextbox().setText(ctx.transPlural(textKey, textKey + "_plural", quantity));
|
||||||
|
|
||||||
func isDone() -> bool:
|
func isDone() -> bool:
|
||||||
if !super.isDone():
|
if !super.isDone():
|
||||||
|
@@ -7,7 +7,8 @@ enum ItemSortType {
|
|||||||
|
|
||||||
class ItemStackNameComparator:
|
class ItemStackNameComparator:
|
||||||
static func _sort(a, b):
|
static func _sort(a, b):
|
||||||
return ITEM.getItemName(a).to_lower() < ITEM.getItemName(b).to_lower()
|
assert(false, "Going to change implementation of this later.")
|
||||||
|
# return ITEM.getItemName(a).to_lower() < ITEM.getItemName(b).to_lower()
|
||||||
|
|
||||||
class ItemStackTypeComparator:
|
class ItemStackTypeComparator:
|
||||||
static func _sort(a, b):
|
static func _sort(a, b):
|
||||||
|
@@ -28,7 +28,7 @@ static func getCategoryTitleKey(cat:Category) -> String:
|
|||||||
@export var category:Category = Category.INGREDIENT
|
@export var category:Category = Category.INGREDIENT
|
||||||
@export var stackable:bool = true
|
@export var stackable:bool = true
|
||||||
|
|
||||||
func getTranslationContext() -> TransContext:
|
func getTransContext() -> TransContext:
|
||||||
var ctx:TransContext = TransContext.new()
|
var ctx:TransContext = TransContext.new()
|
||||||
ctx.addTransPlural("title", title)
|
ctx.addTransPlural("title", title)
|
||||||
ctx.addTrans("description", description_text)
|
ctx.addTrans("description", description_text)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
class_name ItemResource extends Resource
|
class_name ItemResource extends Resource
|
||||||
|
|
||||||
@export var itemType:Item.Type = Item.Type.ONION;
|
@export var itemType:Item.Type = Item.Type.ONION;
|
||||||
@export var count:int = 1;
|
@export var quantity:int = 1;
|
@@ -30,6 +30,7 @@ func isStarted() -> bool:
|
|||||||
func objectiveUpdated(objective:QuestObjective) -> void:
|
func objectiveUpdated(objective:QuestObjective) -> void:
|
||||||
QUEST.questUpdated.emit(self)
|
QUEST.questUpdated.emit(self)
|
||||||
|
|
||||||
func getLocaleData() -> Dictionary[String, String]:
|
func getTransContext() -> TransContext:
|
||||||
var dict: Dictionary[String, String] = {}
|
var ctx:TransContext = TransContext.new()
|
||||||
return dict
|
ctx.addTransPlural("title", title)
|
||||||
|
return ctx
|
||||||
|
@@ -40,8 +40,14 @@ func _onPlayerInventoryUpdated() -> void:
|
|||||||
func isCompleted() -> bool:
|
func isCompleted() -> bool:
|
||||||
return completed
|
return completed
|
||||||
|
|
||||||
func getLocaleData() -> Dictionary[String, String]:
|
func getTransContext() -> TransContext:
|
||||||
var dict:Dictionary[String, String] = {}
|
var ctx = TransContext.new()
|
||||||
dict.item = ITEM.getItemName(itemType, quantity)
|
|
||||||
dict.quantity = LOCALE.formatInteger(quantity)
|
ctx.addTrans("title", title)
|
||||||
return dict
|
ctx.addTrans("description", description)
|
||||||
|
|
||||||
|
if objectiveType == Type.Item:
|
||||||
|
ctx.addInteger("quantity", quantity)
|
||||||
|
ctx.addContext("item", ITEM.getItem(itemType).getTransContext())
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
@@ -1,7 +1,4 @@
|
|||||||
class_name MainMenuScene extends Node
|
class_name MainMenuScene extends Node
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
pass
|
pass
|
||||||
# $Control/Label.text = tr("main_menu.label").format({
|
|
||||||
# inputIcon = "[img=32x32]res://icon.svg[/img]"
|
|
||||||
# })
|
|
@@ -32,16 +32,4 @@ func getItem(type:Item.Type) -> Item:
|
|||||||
return ITEM_MAP[type]
|
return ITEM_MAP[type]
|
||||||
|
|
||||||
func isStackable(itemType:Item.Type) -> bool:
|
func isStackable(itemType:Item.Type) -> bool:
|
||||||
return getItem(itemType).stackable
|
return getItem(itemType).stackable
|
||||||
|
|
||||||
func getItemName(itemType:Item.Type, count:int = 1) -> String:
|
|
||||||
var item = getItem(itemType)
|
|
||||||
return tr_n(item.title, item.title + "_plural", count).format({
|
|
||||||
"count": count
|
|
||||||
})
|
|
||||||
|
|
||||||
func getItemDescription(itemType:Item.Type) -> String:
|
|
||||||
return getItem(itemType).description_text
|
|
||||||
|
|
||||||
func getItemCategory(itemType:Item.Type) -> Item.Category:
|
|
||||||
return getItem(itemType).category
|
|
@@ -44,8 +44,9 @@ func _enter_tree() -> void:
|
|||||||
print("Hello World!")
|
print("Hello World!")
|
||||||
|
|
||||||
var ctx = TransContext.new()
|
var ctx = TransContext.new()
|
||||||
ctx.addContext("item", ITEM.getItem(Item.Type.POTION).getTranslationContext())
|
ctx.addInteger("quantity", 2)
|
||||||
print(ctx.translate("test"))
|
ctx.addContext("item", ITEM.getItem(Item.Type.POTION).getTransContext())
|
||||||
|
print(ctx.trans("test"))
|
||||||
|
|
||||||
func setLocaleFromLocaleString(localeString:String) -> void:
|
func setLocaleFromLocaleString(localeString:String) -> void:
|
||||||
var parts:PackedStringArray = localeString.split("_")
|
var parts:PackedStringArray = localeString.split("_")
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
class_name TransContext
|
class_name TransContext
|
||||||
|
|
||||||
var default:String = "title"
|
var default:String = "title"
|
||||||
var pluralContext:String = "count"
|
var pluralContext:String = "quantity"
|
||||||
var trans:Dictionary[String, String] = {}
|
|
||||||
var transPlural:Dictionary[String, String] = {}
|
|
||||||
var transBool:Dictionary[String, bool] = {}
|
var transBool:Dictionary[String, bool] = {}
|
||||||
var transInteger:Dictionary[String, int] = {}
|
var transInteger:Dictionary[String, int] = {}
|
||||||
var transFloat:Dictionary[String, float] = {}
|
var transFloat:Dictionary[String, float] = {}
|
||||||
|
var transStrings:Dictionary[String, String] = {}
|
||||||
|
var transStringsPlural:Dictionary[String, String] = {}
|
||||||
var subContexts:Dictionary[String, TransContext] = {}
|
var subContexts:Dictionary[String, TransContext] = {}
|
||||||
|
|
||||||
func setDefault(key:String) -> void:
|
func setDefault(key:String) -> void:
|
||||||
@@ -21,15 +21,15 @@ func addContext(key:String, ctx:TransContext) -> void:
|
|||||||
subContexts[key] = ctx
|
subContexts[key] = ctx
|
||||||
|
|
||||||
func addTrans(key:String, transl:String) -> void:
|
func addTrans(key:String, transl:String) -> void:
|
||||||
if trans.has(key):
|
if transStrings.has(key):
|
||||||
assert(false, "Trans String already exists: " + key)
|
assert(false, "Trans String already exists: " + key)
|
||||||
trans[key] = transl
|
transStrings[key] = transl
|
||||||
|
|
||||||
func addTransPlural(key:String, transl:String, suffix:String = "_plural") -> void:
|
func addTransPlural(key:String, transl:String, suffix:String = "_plural") -> void:
|
||||||
if transPlural.has(key + suffix) || transPlural.has(key):
|
if transStringsPlural.has(key + suffix) || transStringsPlural.has(key):
|
||||||
assert(false, "Trans Plural String already exists: " + key)
|
assert(false, "Trans Plural String already exists: " + key)
|
||||||
trans[key] = transl
|
transStrings[key] = transl
|
||||||
transPlural[key] = transl + suffix
|
transStringsPlural[key] = transl + suffix
|
||||||
|
|
||||||
func addBool(key:String, value:bool) -> void:
|
func addBool(key:String, value:bool) -> void:
|
||||||
if transBool.has(key):
|
if transBool.has(key):
|
||||||
@@ -46,24 +46,90 @@ func addFloat(key:String, value:float) -> void:
|
|||||||
assert(false, "Trans Float String already exists: " + key)
|
assert(false, "Trans Float String already exists: " + key)
|
||||||
transFloat[key] = value
|
transFloat[key] = value
|
||||||
|
|
||||||
# func build(parentContext:TransContext = null) -> Dictionary[String, String]:
|
func build(
|
||||||
# var dict:Dictionary[String, String] = {}
|
parent:TransContext = null,
|
||||||
|
parentDict:Dictionary[String, String] = {},
|
||||||
|
key:String = ""
|
||||||
|
) -> Dictionary[String, String]:
|
||||||
|
var dict:Dictionary[String, String] = {}
|
||||||
|
|
||||||
# for transKey in trans.keys():
|
# Handle basic types
|
||||||
# dict[transKey] = trans[transKey]
|
for boolKey in transBool.keys():
|
||||||
|
var value:bool = transBool[boolKey]
|
||||||
|
dict[boolKey] = str(value).to_lower()# TODO: Change to yes/no?
|
||||||
|
|
||||||
# for transKey in transPlural.keys():
|
for intKey in transInteger.keys():
|
||||||
# dict[transKey] = transPlural[transKey]
|
var value:int = transInteger[intKey]
|
||||||
|
dict[intKey] = str(value)
|
||||||
|
|
||||||
# for transKey in transBool.keys():
|
for floatKey in transFloat.keys():
|
||||||
# dict[transKey] = str(transBool[transKey])
|
var value:float = transFloat[floatKey]
|
||||||
|
dict[floatKey] = str(value)
|
||||||
|
|
||||||
# for transKey in transInteger.keys():
|
# Determine the pluralized strings context
|
||||||
# dict[transKey] = str(transInteger[transKey])
|
var count:int = -1
|
||||||
|
if dict.has(pluralContext):
|
||||||
|
count = int(dict[pluralContext])
|
||||||
|
elif parentDict.has(pluralContext):
|
||||||
|
count = int(parentDict[pluralContext])
|
||||||
|
else:
|
||||||
|
count = 1 # Default to 1 if no count is specified
|
||||||
|
|
||||||
# for transKey in transFloat.keys():
|
# Handle pluralized strings
|
||||||
# dict[transKey] = str(transFloat[transKey])
|
for strKey in transStringsPlural.keys():
|
||||||
|
assert(transStrings.has(strKey), "Missing singular translation for: " + strKey)
|
||||||
|
dict[strKey] = tr_n(
|
||||||
|
transStrings[strKey],
|
||||||
|
transStringsPlural[strKey],
|
||||||
|
count
|
||||||
|
)
|
||||||
|
|
||||||
# return dict
|
# Handle non pluralized strings
|
||||||
|
for strKey in transStrings.keys():
|
||||||
|
# Already handled in pluralized strings?
|
||||||
|
if dict.has(strKey):
|
||||||
|
continue
|
||||||
|
dict[strKey] = tr(transStrings[strKey])
|
||||||
|
|
||||||
func translate(key:String) -> String:
|
# Create a super context that contains all the parent translations and ours
|
||||||
|
var superDict = dict.duplicate()
|
||||||
|
superDict.merge(parentDict)
|
||||||
|
|
||||||
|
# Generate sub contexts
|
||||||
|
for subKey in subContexts.keys():
|
||||||
|
var subCtx:TransContext = subContexts[subKey]
|
||||||
|
var subDict:Dictionary[String, String] = subCtx.build(
|
||||||
|
self,
|
||||||
|
superDict,
|
||||||
|
subKey + "."
|
||||||
|
)
|
||||||
|
# Merge with our dictionary
|
||||||
|
dict.merge(subDict)
|
||||||
|
|
||||||
|
print("Trans context before key prepend: ", dict)
|
||||||
|
|
||||||
|
if key != "":
|
||||||
|
# Now prepend the parent key to all keys in the dictionary
|
||||||
|
var newDict:Dictionary[String, String] = {}
|
||||||
|
for k in dict.keys():
|
||||||
|
var newKey:String = key + k
|
||||||
|
newDict[newKey] = dict[k]
|
||||||
|
|
||||||
|
# Handle default key, this turns say "item.title" into just "item"
|
||||||
|
if dict.has(default):
|
||||||
|
var k2 = key.substr(0, key.length() - 1) # Remove trailing dot
|
||||||
|
newDict[k2] = dict[default]
|
||||||
|
|
||||||
|
dict = newDict
|
||||||
|
|
||||||
|
return dict
|
||||||
|
|
||||||
|
func _trReplace(val:String) -> String:
|
||||||
|
var dict = self.build()
|
||||||
|
return val.format(dict)
|
||||||
|
|
||||||
|
func trans(key:String) -> String:
|
||||||
|
return _trReplace(tr(key))
|
||||||
|
|
||||||
|
func transPlural(keySingle:String, keyPlural:String, count:int) -> String:
|
||||||
|
return _trReplace(tr_n(keySingle, keyPlural, count))
|
||||||
|
@@ -63,9 +63,9 @@ func setQuestObjective(objective = null):
|
|||||||
questObjectiveList.select(objective)
|
questObjectiveList.select(objective)
|
||||||
|
|
||||||
# Setup Description
|
# Setup Description
|
||||||
var data = quest.getLocaleData()
|
var ctx = questObjective.getTransContext()
|
||||||
data.merge(questObjective.getLocaleData())
|
ctx.addContext("quest", quest.getTransContext())
|
||||||
questObjectiveInfo.text = tr(questObjective.description).format(data)
|
questObjectiveInfo.text = ctx.trans(questObjective.description)
|
||||||
|
|
||||||
|
|
||||||
func open(questKey = null) -> void:
|
func open(questKey = null) -> void:
|
||||||
|
Reference in New Issue
Block a user