-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create app localization core module (#240)
- Loading branch information
1 parent
75e63aa
commit e146912
Showing
20 changed files
with
138 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
} | ||
|
||
configureJvmTargets() | ||
|
||
kotlin { | ||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(libs.koin.core) | ||
implementation(libs.kotlin.coroutines.core) | ||
} | ||
} | ||
if (isMac()) { | ||
val iosMain by getting | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...calization/src/commonMain/kotlin/br/alexandregpereira/hunter/localization/Localization.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package br.alexandregpereira.hunter.localization | ||
|
||
interface AppLocalization { | ||
|
||
fun getLanguage(): Language | ||
} | ||
|
||
interface MutableAppLocalization : AppLocalization { | ||
|
||
fun setLanguage(language: String) | ||
} | ||
|
||
internal class AppLocalizationImpl : MutableAppLocalization { | ||
|
||
private var language: Language = Language.ENGLISH | ||
|
||
override fun getLanguage(): Language { | ||
return language | ||
} | ||
|
||
override fun setLanguage(language: String) { | ||
this.language = Language.entries.firstOrNull { it.code == language } ?: Language.ENGLISH | ||
} | ||
} | ||
|
||
enum class Language(val code: String) { | ||
ENGLISH("en-us"), | ||
PORTUGUESE("pt-br") | ||
} |
12 changes: 12 additions & 0 deletions
12
...n/src/commonMain/kotlin/br/alexandregpereira/hunter/localization/di/LocalizationModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package br.alexandregpereira.hunter.localization.di | ||
|
||
import br.alexandregpereira.hunter.localization.AppLocalization | ||
import br.alexandregpereira.hunter.localization.AppLocalizationImpl | ||
import br.alexandregpereira.hunter.localization.MutableAppLocalization | ||
import org.koin.dsl.module | ||
|
||
val localizationModule = module { | ||
single { AppLocalizationImpl() } | ||
factory<MutableAppLocalization> { get<AppLocalizationImpl>() } | ||
factory<AppLocalization> { get<AppLocalizationImpl>() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
.../commonMain/kotlin/br/alexandregpereira/hunter/spell/compendium/SpellCompendiumStrings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package br.alexandregpereira.hunter.spell.compendium | ||
|
||
import br.alexandregpereira.hunter.localization.Language | ||
|
||
internal class SpellCompendiumEnStrings : SpellCompendiumStrings { | ||
override val searchResults: (Int) -> String = { count -> "$count results" } | ||
override val cantrips: String = "Cantrips" | ||
override val level: (Int) -> String = { level -> "Level $level" } | ||
override val searchLabel: String = "Search" | ||
} | ||
|
||
internal class SpellCompendiumPtStrings : SpellCompendiumStrings { | ||
override val searchResults: (Int) -> String = { count -> "$count resultados" } | ||
override val cantrips: String = "Truques" | ||
override val level: (Int) -> String = { level -> "${level}º Círculo" } | ||
override val searchLabel: String = "Buscar" | ||
} | ||
|
||
internal interface SpellCompendiumStrings { | ||
val searchResults: (Int) -> String | ||
val cantrips: String | ||
val level: (Int) -> String | ||
val searchLabel: String | ||
} | ||
|
||
internal fun getSpellCompendiumStrings(lang: Language): SpellCompendiumStrings { | ||
return when (lang) { | ||
Language.ENGLISH -> SpellCompendiumEnStrings() | ||
Language.PORTUGUESE -> SpellCompendiumPtStrings() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters