From 73e67becb35caa1f805a4e783ec981482324eb6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Gran=C3=A1t?= Date: Tue, 30 Jul 2024 10:58:53 +0200 Subject: [PATCH] fix: snake language template placeholder --- .../service/export/ExportFilePathProvider.kt | 2 +- .../formats/json/out/JsonFileExporterTest.kt | 50 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/backend/data/src/main/kotlin/io/tolgee/service/export/ExportFilePathProvider.kt b/backend/data/src/main/kotlin/io/tolgee/service/export/ExportFilePathProvider.kt index 2154f615e9..85ee716f5a 100644 --- a/backend/data/src/main/kotlin/io/tolgee/service/export/ExportFilePathProvider.kt +++ b/backend/data/src/main/kotlin/io/tolgee/service/export/ExportFilePathProvider.kt @@ -107,7 +107,7 @@ class ExportFilePathProvider( ) .replacePlaceholder( ExportFilePathPlaceholder.SNAKE_LANGUAGE_TAG, - convertBCP47ToAndroidResourceFormat(getSnakeLanguageTag(languageTag)), + getSnakeLanguageTag(languageTag), ) } diff --git a/backend/data/src/test/kotlin/io/tolgee/unit/formats/json/out/JsonFileExporterTest.kt b/backend/data/src/test/kotlin/io/tolgee/unit/formats/json/out/JsonFileExporterTest.kt index 619093dfca..10d3fea448 100644 --- a/backend/data/src/test/kotlin/io/tolgee/unit/formats/json/out/JsonFileExporterTest.kt +++ b/backend/data/src/test/kotlin/io/tolgee/unit/formats/json/out/JsonFileExporterTest.kt @@ -193,7 +193,7 @@ class JsonFileExporterTest { translations = buildExportTranslationList { add( - languageTag = "cs", + languageTag = "cs-CZ", keyName = "item", text = "A", ) @@ -206,7 +206,53 @@ class JsonFileExporterTest { val files = exporter.produceFiles() - files["cs/hello.json"].assert.isNotNull() + files["cs-CZ/hello.json"].assert.isNotNull() + } + + @Test + fun `honors the provided fileStructureTemplate (snakeCase)`() { + val exporter = + getExporter( + translations = + buildExportTranslationList { + add( + languageTag = "cs-CZ", + keyName = "item", + text = "A", + ) + }.translations, + exportParams = + ExportParams().also { + it.fileStructureTemplate = "{snakeLanguageTag}/hello/{namespace}.{extension}" + }, + ) + + val files = exporter.produceFiles() + + files["cs_CZ/hello.json"].assert.isNotNull() + } + + @Test + fun `honors the provided fileStructureTemplate (androidLanguageTag)`() { + val exporter = + getExporter( + translations = + buildExportTranslationList { + add( + languageTag = "cs-CZ", + keyName = "item", + text = "A", + ) + }.translations, + exportParams = + ExportParams().also { + it.fileStructureTemplate = "{androidLanguageTag}/hello/{namespace}.{extension}" + }, + ) + + val files = exporter.produceFiles() + + files["cs-rCZ/hello.json"].assert.isNotNull() } private fun Map.getFileTextContent(fileName: String): String {