-
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add simple properties file importer (#2050)
See #2042 --------- Co-authored-by: Benoît Allard <benoit.allard@sla.de>
- Loading branch information
1 parent
1e5cdbb
commit 11dd90f
Showing
14 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...end/data/src/main/kotlin/io/tolgee/service/dataImport/processors/PropertyFileProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.tolgee.service.dataImport.processors | ||
|
||
import java.util.Properties | ||
|
||
class PropertyFileProcessor( | ||
override val context: FileProcessorContext, | ||
) : ImportFileProcessor() { | ||
override fun process() { | ||
val props = Properties() | ||
props.load(context.file.inputStream) | ||
props.entries.forEachIndexed { idx, it -> | ||
context.addTranslation(it.key.toString(), languageNameGuesses[0], it.value, idx) | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...st/kotlin/io/tolgee/unit/service/dataImport/processors/processors/PropertiesParserTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.tolgee.unit.service.dataImport.processors.processors | ||
|
||
import io.tolgee.dtos.dataImport.ImportFileDto | ||
import io.tolgee.model.dataImport.Import | ||
import io.tolgee.model.dataImport.ImportFile | ||
import io.tolgee.service.dataImport.processors.FileProcessorContext | ||
import io.tolgee.service.dataImport.processors.PropertyFileProcessor | ||
import org.assertj.core.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.mockito.kotlin.mock | ||
import java.io.File | ||
|
||
class PropertiesParserTest { | ||
private lateinit var importMock: Import | ||
private lateinit var importFile: ImportFile | ||
private lateinit var importFileDto: ImportFileDto | ||
private lateinit var fileProcessorContext: FileProcessorContext | ||
|
||
@BeforeEach | ||
fun setup() { | ||
importMock = mock() | ||
importFile = ImportFile("messages_en.properties", importMock) | ||
importFileDto = ImportFileDto( | ||
"messages_en.properties", | ||
File("src/test/resources/import/example.properties") | ||
.inputStream() | ||
) | ||
fileProcessorContext = FileProcessorContext(importFileDto, importFile) | ||
} | ||
|
||
@Test | ||
fun `returns correct parsed result`() { | ||
PropertyFileProcessor(fileProcessorContext).process() | ||
Assertions.assertThat(fileProcessorContext.languages).hasSize(1) | ||
Assertions.assertThat(fileProcessorContext.translations).hasSize(4) | ||
val text = fileProcessorContext.translations["Register"]?.get(0)?.text | ||
Assertions.assertThat(text).isEqualTo("Veuillez vous enregistrer sur la page suivante.") | ||
val multiLineText = fileProcessorContext.translations["Cleanup"]?.get(0)?.text | ||
Assertions.assertThat(multiLineText).hasLineCount(3) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Localization_tools=Lokaliza?ní nástroje | ||
|
||
Welcome=Herzlich Wilkommen | ||
# This is a comment | ||
Register=Veuillez vous enregistrer \ | ||
sur la page suivante. | ||
Cleanup=Veeg uw\n voeten\n voordat u binnengaat. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters