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.config.resources.ResourceFileProvider
import ru.pocketbyte.locolaser.mobile.resource.file.IosPluralResourceFile
import ru.pocketbyte.locolaser.mobile.resource.file.IosResourceFile
import ru.pocketbyte.locolaser.resource.file.ResourceFile
import java.io.File
/**
* Resource implementation for iOS platform.
*
* @author Denis Shurygin
*/
class IosResources(
resourcesDir: File,
name: String,
resourceFileProvider: ResourceFileProvider,
filter: ((key: String) -> Boolean)?
) : AbsIosStringsResources(resourcesDir, name, resourceFileProvider, filter) {
companion object {
const val PLURAL_RES_FILE_EXTENSION = "stringsdict"
}
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]
)
}
}
}
private fun getPluralFileForLocale(locale: String): File {
return getFileForLocale(locale, extension = PLURAL_RES_FILE_EXTENSION)
}
override fun allFiles(locales: Set): List {
return locales.map { getFileForLocale(it) } +
locales.map { getPluralFileForLocale(it) }
}
}