All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.pocketbyte.locolaser.mobile.resource.IosResources.kt Maven / Gradle / Ivy

Go to download

Implementation of platform for LocoLaser tool to work with Android and iOS platforms.

There is a newer version: 2.5.0
Show newest version
/*
 * 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) }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy