mirror of
https://github.com/yairm210/Unciv.git
synced 2025-03-13 19:39:34 +07:00
Added try/catch on reading the translation file (some phones don't support UTF-8???)
You can always pass the language screen even if we don't read the percentage files We read the percentage files from the INTERNAL NOT THE LOCAL OBVIOUSLY
This commit is contained in:
parent
6d666e168b
commit
3f0e33df89
android
core/src/com/unciv
models/translations
ui/worldscreen/optionstable
@ -21,8 +21,8 @@ android {
|
||||
applicationId "com.unciv.app"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 29
|
||||
versionCode 349
|
||||
versionName "3.4.1"
|
||||
versionCode 350
|
||||
versionName "3.4.1-patch1"
|
||||
|
||||
archivesBaseName = "Unciv"
|
||||
}
|
||||
|
@ -66,11 +66,10 @@ class TranslationFileReader{
|
||||
|
||||
fun readLanguagePercentages():HashMap<String,Int>{
|
||||
|
||||
|
||||
val hashmap = HashMap<String,Int>()
|
||||
val percentageFile = Gdx.files.local(percentagesFileLocation)
|
||||
val percentageFile = Gdx.files.internal(percentagesFileLocation)
|
||||
if(!percentageFile.exists()) return hashmap
|
||||
for(line in Gdx.files.local(percentagesFileLocation).reader().readLines()){
|
||||
for(line in percentageFile.reader().readLines()){
|
||||
val splitLine = line.split(" = ")
|
||||
hashmap[splitLine[0]]=splitLine[1].toInt()
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import kotlin.collections.HashMap
|
||||
class Translations : LinkedHashMap<String, TranslationEntry>(){
|
||||
|
||||
var percentCompleteOfLanguages = HashMap<String,Int>()
|
||||
.apply { put("English",100) } // So even if we don't manage to load the percentages, we can still pass the language screen
|
||||
|
||||
fun get(text:String,language:String): String {
|
||||
if(!hasTranslation(text,language)) return text
|
||||
@ -35,8 +36,15 @@ class Translations : LinkedHashMap<String, TranslationEntry>(){
|
||||
|
||||
val translationFileName = "jsons/translationsByLanguage/$language.properties"
|
||||
if (!Gdx.files.internal(translationFileName).exists()) return
|
||||
val languageTranslations = TranslationFileReader()
|
||||
|
||||
val languageTranslations:HashMap<String,String>
|
||||
try { // On some devices we get a weird UnsupportedEncodingException
|
||||
// which is super odd because everyone should support UTF-8
|
||||
languageTranslations = TranslationFileReader()
|
||||
.read(translationFileName)
|
||||
}catch (ex:Exception){
|
||||
return
|
||||
}
|
||||
|
||||
for (translation in languageTranslations) {
|
||||
if (!containsKey(translation.key))
|
||||
|
@ -264,14 +264,14 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr
|
||||
}
|
||||
|
||||
private fun addLanguageSelectBox(innerTable: PopupTable) {
|
||||
innerTable.add("Language".toLabel())
|
||||
val languageSelectBox = SelectBox<Language>(skin)
|
||||
val languageArray = Array<Language>()
|
||||
val ruleSet = worldScreen.gameInfo.ruleSet
|
||||
UncivGame.Current.translations.percentCompleteOfLanguages
|
||||
.map { Language(it.key, if(it.key=="English") 100 else it.value) }
|
||||
.sortedByDescending { it.percentComplete }
|
||||
.forEach { languageArray.add(it) }
|
||||
if(languageArray.size==0) return
|
||||
innerTable.add("Language".toLabel())
|
||||
languageSelectBox.items = languageArray
|
||||
val matchingLanguage = languageArray.firstOrNull { it.language == UncivGame.Current.settings.language }
|
||||
languageSelectBox.selected = if (matchingLanguage != null) matchingLanguage else languageArray.first()
|
||||
|
Loading…
Reference in New Issue
Block a user