Skip to content

Commit 9e5e03a

Browse files
refactor: Make CoreImportFilesProcessor.processTranslations less tangled
1 parent a3276b4 commit 9e5e03a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

backend/data/src/main/kotlin/io/tolgee/service/dataImport/CoreImportFilesProcessor.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,19 @@ class CoreImportFilesProcessor(
323323
}
324324

325325
private fun FileProcessorContext.processTranslations() {
326-
this.translations.forEach { entry ->
327-
val keyEntity = getOrCreateKey(entry.key)
328-
entry.value.forEach { newTranslation ->
329-
processTranslation(newTranslation, keyEntity)
326+
val translationsByKeys = translations.mapKeys { (keyName, _) ->
327+
getOrCreateKey(keyName).apply {
328+
shouldBeImported = shouldImportKey(name)
330329
}
331-
keyEntity.shouldBeImported = shouldImportKey(keyEntity.name)
332330
}
331+
332+
translationsByKeys.forEach { (key, translations) ->
333+
translations.forEach {
334+
it.key = key
335+
processTranslation(it)
336+
}
337+
}
338+
333339
if (saveData) {
334340
importDataManager.saveAllStoredTranslations()
335341
}
@@ -344,9 +350,7 @@ class CoreImportFilesProcessor(
344350

345351
private fun FileProcessorContext.processTranslation(
346352
newTranslation: ImportTranslation,
347-
keyEntity: ImportKey,
348353
) {
349-
newTranslation.key = keyEntity
350354
val (isCollision, fileCollisions) = checkForInFileCollisions(newTranslation)
351355
if (isCollision) {
352356
fileEntity.addIssues(fileCollisions)

0 commit comments

Comments
 (0)