ru.pocketbyte.locolaser.mobile.resource.IosResources.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resource-mobile Show documentation
Show all versions of resource-mobile Show documentation
Implementation of platform for LocoLaser tool to work with Android and iOS platforms.
/*
* Copyright © 2017 Denis Shurygin. All rights reserved.
* Licensed under the Apache License, Version 2.0
*/
package ru.pocketbyte.locolaser.mobile.resource
import ru.pocketbyte.locolaser.mobile.resource.file.IosPluralResourceFile
import ru.pocketbyte.locolaser.mobile.resource.file.IosResourceFile
import ru.pocketbyte.locolaser.resource.file.ResourceFile
import ru.pocketbyte.locolaser.resource.formatting.FormattingType
import ru.pocketbyte.locolaser.resource.formatting.JavaFormattingType
import ru.pocketbyte.locolaser.summary.FileSummary
import java.io.File
/**
* Resource implementation for iOS platform.
*
* @author Denis Shurygin
*/
class IosResources(
resourcesDir: File,
name: String,
filter: ((key: String) -> Boolean)?
) : AbsIosStringsResources(resourcesDir, name, filter) {
companion object {
const val PLURAL_RES_FILE_EXTENSION = ".stringsdict"
}
override val formattingType: FormattingType = JavaFormattingType
override fun getResourceFiles(locales: Set?): Array? {
val localesArray = locales?.toTypedArray() ?: return null
return Array(locales.size * 2) { i->
val index: Int = i / 2
if (i % 2 == 0) {
IosResourceFile(getFileForLocale(localesArray[index]), localesArray[index])
}
else {
IosPluralResourceFile(getPluralFileForLocale(localesArray[index]), localesArray[index])
}
}
}
override fun summaryForLocale(locale: String): FileSummary {
return FileSummary(arrayOf(getFileForLocale(locale), getPluralFileForLocale(locale)))
}
private fun getPluralFileForLocale(locale: String): File {
val localeFolder = File(directory, getLocaleDirName(locale))
localeFolder.mkdirs()
return File(localeFolder, name + PLURAL_RES_FILE_EXTENSION)
}
}