mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-12 19:10:12 +07:00
Simplified translation file writing by treating all placeholders with a single number in the same way
This commit is contained in:
parent
95e1e8279d
commit
ceb456acab
@ -193,24 +193,18 @@ object TranslationFileWriter {
|
|||||||
|
|
||||||
fun submitString(item: Any) {
|
fun submitString(item: Any) {
|
||||||
val string = item.toString()
|
val string = item.toString()
|
||||||
// substitute the regex for "Bonus/Penalty vs ..."
|
|
||||||
val match = Regex(BattleDamage.BONUS_VS_UNIT_TYPE).matchEntire(string)
|
|
||||||
when {
|
|
||||||
match != null ->
|
|
||||||
resultStrings!!.add("${match.groupValues[1]} vs [unitType] = ")
|
|
||||||
|
|
||||||
// substitute the regex for the bonuses, etc.
|
val parameters = string.getPlaceholderParameters()
|
||||||
string.startsWith(MapUnit.BONUS_WHEN_INTERCEPTING)
|
var stringToTranslate = string
|
||||||
|| string.startsWith(UnitActions.CAN_UNDERTAKE)
|
if (parameters.size == 1 && parameters[0].toIntOrNull() != null)
|
||||||
|| string.endsWith(MapUnit.CHANCE_TO_INTERCEPT_AIR_ATTACKS)
|
stringToTranslate = string.replace(parameters[0], "amount")
|
||||||
|| Regex(BattleDamage.BONUS_AS_ATTACKER).matchEntire(string) != null
|
else {
|
||||||
|| Regex(BattleDamage.HEAL_WHEN_KILL).matchEntire(string) != null -> {
|
// substitute the regex for "Bonus/Penalty vs ..."
|
||||||
val updatedString = string.replace("\\[\\d+(?=])]".toRegex(), "[amount]")
|
val match = Regex(BattleDamage.BONUS_VS_UNIT_TYPE).matchEntire(string)
|
||||||
resultStrings!!.add("$updatedString = ")
|
if (match != null) stringToTranslate = "${match.groupValues[1]} vs [unitType]"
|
||||||
}
|
|
||||||
else ->
|
|
||||||
resultStrings!!.add("$string = ")
|
|
||||||
}
|
}
|
||||||
|
resultStrings!!.add("$stringToTranslate = ")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fun serializeElement(element: Any) {
|
fun serializeElement(element: Any) {
|
||||||
@ -243,23 +237,24 @@ object TranslationFileWriter {
|
|||||||
return generatedStrings
|
return generatedStrings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val untranslatableFieldSet = setOf (
|
||||||
|
"aiFreeTechs", "aiFreeUnits", "attackSound", "building",
|
||||||
|
"cannotBeBuiltWith", "cultureBuildings", "improvement", "improvingTech",
|
||||||
|
"obsoleteTech", "occursOn", "prerequisites", "promotions",
|
||||||
|
"providesFreeBuilding", "replaces", "requiredBuilding", "requiredBuildingInAllCities",
|
||||||
|
"requiredNearbyImprovedResources", "requiredResource", "requiredTech", "requires",
|
||||||
|
"resourceTerrainAllow", "revealedBy", "startBias", "techRequired",
|
||||||
|
"terrainsCanBeBuiltOn", "terrainsCanBeFoundOn", "turnsInto", "uniqueTo", "upgradesTo"
|
||||||
|
)
|
||||||
|
|
||||||
private fun isFieldTranslatable(field: Field, fieldValue: Any?): Boolean {
|
private fun isFieldTranslatable(field: Field, fieldValue: Any?): Boolean {
|
||||||
// Exclude fields by name that contain references to items defined elsewhere
|
// Exclude fields by name that contain references to items defined elsewhere
|
||||||
// - the definition should cause the inclusion in our translatables list, not the reference.
|
// - the definition should cause the inclusion in our translatables list, not the reference.
|
||||||
// This prevents duplication within the base game (e.g. Mines were duplicated by being output
|
// This prevents duplication within the base game (e.g. Mines were duplicated by being output
|
||||||
// by both TerrainResources and TerrainImprovements) and duplication of base game items into
|
// by both TerrainResources and TerrainImprovements) and duplication of base game items into
|
||||||
// mods. Note "uniques" is not in this list and might still generate dupes - TODO
|
|
||||||
return fieldValue != null &&
|
return fieldValue != null &&
|
||||||
fieldValue != "" &&
|
fieldValue != "" &&
|
||||||
field.name !in setOf (
|
field.name !in untranslatableFieldSet
|
||||||
"aiFreeTechs", "aiFreeUnits", "attackSound", "building",
|
|
||||||
"cannotBeBuiltWith", "cultureBuildings", "improvement", "improvingTech",
|
|
||||||
"obsoleteTech", "occursOn", "prerequisites", "promotions",
|
|
||||||
"providesFreeBuilding", "replaces", "requiredBuilding", "requiredBuildingInAllCities",
|
|
||||||
"requiredNearbyImprovedResources", "requiredResource", "requiredTech", "requires",
|
|
||||||
"resourceTerrainAllow", "revealedBy", "startBias", "techRequired",
|
|
||||||
"terrainsCanBeBuiltOn", "terrainsCanBeFoundOn", "turnsInto", "uniqueTo", "upgradesTo"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getJavaClassByName(name: String): Class<Any> {
|
private fun getJavaClassByName(name: String): Class<Any> {
|
||||||
|
Loading…
Reference in New Issue
Block a user