Skip to content
10 changes: 5 additions & 5 deletions backend/data/src/main/kotlin/io/tolgee/formats/ExportFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ enum class ExportFormat(
"application/x-xliff+xml",
defaultFileStructureTemplate = "{languageTag}.{extension}",
),
APPLE_XCSTRINGS(
"xcstrings",
"application/json",
defaultFileStructureTemplate = "Localizable.{extension}",
),
ANDROID_XML(
"xml",
"application/xml",
Expand All @@ -48,4 +43,9 @@ enum class ExportFormat(
CSV("csv", "text/csv"),
RESX_ICU("resx", "text/microsoft-resx"),
XLSX("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
APPLE_XCSTRINGS(
"xcstrings",
"application/json",
defaultFileStructureTemplate = "Localizable.{extension}",
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ data class FileProcessorContext(

val key = getOrCreateKey(keyName)
metadata?.let { meta ->
meta["comment"]?.takeIf { it is String }?.let {
addKeyDescription(keyName, it as String)
}
addKeyDescription(keyName, meta["comment"]?.toString())
}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.ibm.icu.util.ULocale
import io.tolgee.constants.Message
import io.tolgee.dtos.IExportParams
import io.tolgee.exceptions.BadRequestException
import io.tolgee.formats.ExportFormat
import io.tolgee.service.export.dataProvider.ExportTranslationView

class ExportFilePathProvider(
Expand All @@ -18,14 +19,6 @@ class ExportFilePathProvider(
languageTag: String? = null,
replaceExtension: Boolean = true,
): String {
// If no template is provided, use a default template for xcstrings
if (params.fileStructureTemplate == null) {
return when {
namespace.isNullOrEmpty() -> "Localizable.xcstrings"
else -> "$namespace.xcstrings"
}
}

val template = validateAndGetTemplate()
return template
.replacePlaceholder(ExportFilePathPlaceholder.NAMESPACE, namespace ?: "")
Expand Down Expand Up @@ -60,19 +53,21 @@ class ExportFilePathProvider(
}

private fun validateTemplate() {
val containsLanguageTag =
arrayOf(
ExportFilePathPlaceholder.LANGUAGE_TAG,
ExportFilePathPlaceholder.ANDROID_LANGUAGE_TAG,
ExportFilePathPlaceholder.SNAKE_LANGUAGE_TAG,
).any { getTemplate().contains(it.placeholder) }

if (!containsLanguageTag) {
throw getMissingPlaceholderException(
ExportFilePathPlaceholder.LANGUAGE_TAG,
ExportFilePathPlaceholder.ANDROID_LANGUAGE_TAG,
ExportFilePathPlaceholder.SNAKE_LANGUAGE_TAG,
)
if (params.format !in listOf(ExportFormat.APPLE_XCSTRINGS)) {
val containsLanguageTag =
arrayOf(
ExportFilePathPlaceholder.LANGUAGE_TAG,
ExportFilePathPlaceholder.ANDROID_LANGUAGE_TAG,
ExportFilePathPlaceholder.SNAKE_LANGUAGE_TAG,
).any { getTemplate().contains(it.placeholder) }

if (!containsLanguageTag) {
throw getMissingPlaceholderException(
ExportFilePathPlaceholder.LANGUAGE_TAG,
ExportFilePathPlaceholder.ANDROID_LANGUAGE_TAG,
ExportFilePathPlaceholder.SNAKE_LANGUAGE_TAG,
)
}
}

val containsExtension = getTemplate().contains(ExportFilePathPlaceholder.EXTENSION.placeholder)
Expand Down
Loading