Skip to content

Commit

Permalink
fix: Import -> Collisions between files handling (#2612)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCizmar authored Oct 21, 2024
1 parent d9a95ce commit 8f085a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,28 @@ class V2ImportControllerAddFilesTest : ProjectAuthControllerTest("/v2/projects/"
}
}

@Test
fun `correctly reports collisions between files`() {
val testData = ImportCleanTestData()
testDataService.saveTestData(testData.root)

loginAsUser(testData.userAccount.username)
performImport(
projectId = testData.project.id,
listOf(
Pair("en.json", simpleJson),
),
).andIsOk
performImport(
projectId = testData.project.id,
listOf(
Pair("en.json", simpleJson),
),
).andIsOk.andPrettyPrint.andAssertThatJson {
node("result._embedded.languages[1].importFileIssueCount").isEqualTo(1)
}
}

private fun validateSavedJsonImportData(
project: Project,
userAccount: UserAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import io.tolgee.api.IImportSettings
import io.tolgee.formats.CollisionHandler
import io.tolgee.formats.isSamePossiblePlural
import io.tolgee.model.Language
import io.tolgee.model.dataImport.*
import io.tolgee.model.dataImport.Import
import io.tolgee.model.dataImport.ImportFile
import io.tolgee.model.dataImport.ImportKey
import io.tolgee.model.dataImport.ImportLanguage
import io.tolgee.model.dataImport.ImportTranslation
import io.tolgee.model.dataImport.issues.ImportFileIssue
import io.tolgee.model.dataImport.issues.issueTypes.FileIssueType
import io.tolgee.model.dataImport.issues.paramTypes.FileIssueParamType
Expand Down Expand Up @@ -236,7 +240,7 @@ class ImportDataManager(

fun resetCollisionsBetweenFiles(
editedLanguage: ImportLanguage,
oldExistingLanguage: Language?,
oldExistingLanguage: Language? = null,
) {
val affectedLanguages =
storedLanguages.filter {
Expand Down Expand Up @@ -314,7 +318,7 @@ class ImportDataManager(
)

storedTranslations.firstOrNull {
it.isSelectedToImport && it.text != newTranslation.text
it.isSelectedToImport
}?.let { collision ->
val handled = tryHandleUsingCollisionHandlers(listOf(newTranslation) + storedTranslations)
if (handled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ val IGNORED_REGEXES by lazy {
"^[\\w-_]+\\.xcloc/contents.json$".toRegex(),
"^.+\\.xcloc/Source Contents/Localizable.xcstrings$".toRegex(),
"^.+\\.xcloc/Source Contents/.*InfoPlist.xcstrings$".toRegex(),
// .DS_Store files
"""(.*/|^)\.DS_Store$""".toRegex(),
)
}

Expand Down

0 comments on commit 8f085a6

Please sign in to comment.