main.phraseapp.repositories.operations.Downloader.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-client Show documentation
Show all versions of gradle-client Show documentation
JVM client to interact with Phrase via its API.
The newest version!
package phraseapp.repositories.operations
import kotlinx.coroutines.coroutineScope
import phraseapp.internal.platforms.Platform
import phraseapp.internal.printers.FileOperation
import phraseapp.internal.xml.Resource
import phraseapp.network.*
import phraseapp.parsers.xml.DEFAULT_IGNORE_COMMENTS
import phraseapp.repositories.operations.helpers.LocalHelper
import phraseapp.repositories.operations.helpers.PrinterHelper
import phraseapp.repositories.operations.helpers.ReducerHelper
class Downloader(
platform: Platform,
buildDir: String,
fileOperation: FileOperation,
private val network: PhraseAppNetworkDataSource
) {
private val localHelper = LocalHelper(platform)
private val reducerHelper = ReducerHelper(platform)
private val printerHelper = PrinterHelper(platform, buildDir, fileOperation)
suspend fun download(
resFolders: Map>,
overrideDefaultFile: Boolean = DEFAULT_OVERRIDE_DEFAULT_FILE,
exceptions: Map = DEFAULT_EXCEPTIONS,
placeholder: Boolean = DEFAULT_PLACEHOLDER,
localeNameRegex: String = DEFAULT_REGEX,
ignoreComments: Boolean = DEFAULT_IGNORE_COMMENTS,
allowedLocaleCodes: List = DEFAULT_ALLOWED_LOCALE_CODES,
dontDeleteKeys: Boolean = DEFAULT_DONT_DELETE_KEYS,
) = coroutineScope {
val strings = localHelper.getStringsFileByResFolder(resFolders)
val locales = network.downloadAllLocales(
overrideDefaultFile,
exceptions,
placeholder,
localeNameRegex,
allowedLocaleCodes
)
val resources = reducerHelper.reduceKeysForAllStringsFilesAndForAllLocales(
strings,
locales,
ignoreComments,
dontDeleteKeys
)
printerHelper.printResources(resources)
printerHelper.printLocales(getTypes(resources))
return@coroutineScope resources
}
private fun getTypes(configurations: Map>): List =
configurations.entries.first().value.keys.toList()
}
sealed class ResFolderType
object DefaultType : ResFolderType()
class LanguageType(val language: String) : ResFolderType()
class LocaleType(val language: String, val country: String) : ResFolderType()