Use enum to generate parameter names when translating - more accurate than auto-detect by parameter name!

This commit is contained in:
yairm210
2021-09-17 14:10:40 +03:00
parent c2fa1366bb
commit fa462d830f
2 changed files with 11 additions and 8 deletions

View File

@ -18,7 +18,7 @@ enum class UniqueType(val text:String, val replacedBy: UniqueType? = null) {
/** For uniques that have "special" parameters that can accept multiple types, we can override them manually
* For 95% of cases, auto-matching is fine. */
private val parameterTypeMap = ArrayList<List<UniqueParameterType>>()
val parameterTypeMap = ArrayList<List<UniqueParameterType>>()
init {
for (placeholder in text.getPlaceholderParameters()) {

View File

@ -244,16 +244,19 @@ object TranslationFileWriter {
generatedStrings[filename] = mutableSetOf()
val resultStrings = generatedStrings[filename]!!
fun submitString(item: Any) {
val string = item.toString()
val parameters = string.getPlaceholderParameters()
fun submitString(string: String) {
val unique = Unique(string)
var stringToTranslate = string
val existingParameterNames = HashSet<String>()
if (parameters.any()) {
for (parameter in parameters) {
if (unique.params.isNotEmpty()) {
for ((index,parameter) in unique.params.withIndex()) {
var parameterName = when {
unique.type != null -> {
val possibleParameterTypes = unique.type.parameterTypeMap[index]
// for multiple types. will look like "[unitName/buildingName]"
possibleParameterTypes.joinToString("/") { it.parameterName }
}
parameter.toFloatOrNull() != null -> "amount"
Stat.values().any { it.name == parameter } -> "stat"
parameter in tileFilterMap -> "tileFilter"
@ -320,7 +323,7 @@ object TranslationFileWriter {
is kotlin.collections.List<*> ->
for (item in fieldValue)
if (item is String) submitString(item) else serializeElement(item!!)
else -> submitString(fieldValue)
else -> submitString(fieldValue.toString())
}
}
}