diff --git a/backend/app/src/main/kotlin/io/tolgee/api/v2/controllers/translation/V2TranslationsController.kt b/backend/app/src/main/kotlin/io/tolgee/api/v2/controllers/translation/V2TranslationsController.kt index 6c7e230545..78d3609b43 100644 --- a/backend/app/src/main/kotlin/io/tolgee/api/v2/controllers/translation/V2TranslationsController.kt +++ b/backend/app/src/main/kotlin/io/tolgee/api/v2/controllers/translation/V2TranslationsController.kt @@ -65,6 +65,7 @@ import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController import org.springframework.web.context.request.WebRequest import java.util.* @@ -130,7 +131,8 @@ e.g. For key "home.header.title" would result in {"home": {"header": {"title": " When null, resulting file will be a flat key-value object. """, ) - structureDelimiter: Char? = '.', + @RequestParam(value = "structureDelimiter", defaultValue = ".", required = false) + structureDelimiter: Char?, request: WebRequest ): ResponseEntity>? { val lastModified: Long = projectTranslationLastModifiedManager.getLastModified(projectHolder.project.id) @@ -142,7 +144,7 @@ When null, resulting file will be a flat key-value object. val response = translationService.getTranslations( languageTags = languages, projectId = projectHolder.project.id, - structureDelimiter = structureDelimiter + structureDelimiter = request.getStructureDelimiter() ) return ResponseEntity.ok() @@ -153,6 +155,17 @@ When null, resulting file will be a flat key-value object. ) } + /** + * It has to be handled manually since spring returns default value even when empty value provided + */ + private fun WebRequest.getStructureDelimiter(): Char? { + val structureDelimiterParam = this.parameterMap["structureDelimiter"]?.first() ?: return '.' + if (structureDelimiterParam == "") { + return null + } + return structureDelimiterParam.toCharArray().first() + } + @PutMapping("") @AccessWithApiKey(scopes = [ApiScope.TRANSLATIONS_EDIT]) @AccessWithProjectPermission(permission = Permission.ProjectPermissionType.TRANSLATE) diff --git a/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translations/v2TranslationsController/V2TranslationsControllerViewTest.kt b/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translations/v2TranslationsController/V2TranslationsControllerViewTest.kt index 70c7555d7d..4cafe80952 100644 --- a/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translations/v2TranslationsController/V2TranslationsControllerViewTest.kt +++ b/backend/app/src/test/kotlin/io/tolgee/api/v2/controllers/translations/v2TranslationsController/V2TranslationsControllerViewTest.kt @@ -326,6 +326,9 @@ class V2TranslationsControllerViewTest : ProjectAuthControllerTest("/v2/projects performProjectAuthGet("/translations/en,de?structureDelimiter=+").andIsOk.andAssertThatJson { node("en.hello.i.am.plus.scoped").isEqualTo("yupee!") } + performProjectAuthGet("/translations/en,de").andIsOk.andAssertThatJson { + node("en.hello.i.am.scoped").isEqualTo("yupee!") + } } @ProjectApiKeyAuthTestMethod(scopes = [ApiScope.TRANSLATIONS_VIEW])