mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-26 13:27:22 -04:00
Fix error due changing language on Android < 4.4 (#1502)
This commit is contained in:
parent
7d746df5a2
commit
0b8145cba5
@ -1,14 +1,18 @@
|
|||||||
package com.unciv.models.translations
|
package com.unciv.models.translations
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import java.nio.charset.Charset
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
class TranslationFileReader{
|
class TranslationFileReader{
|
||||||
|
|
||||||
|
private val percentagesFileLocation = "jsons/translationsByLanguage/completionPercentages.properties"
|
||||||
|
private val charset = Charset.forName("UTF-8").name()
|
||||||
|
|
||||||
fun read(translationFile: String): LinkedHashMap<String, String> {
|
fun read(translationFile: String): LinkedHashMap<String, String> {
|
||||||
val translations = LinkedHashMap<String, String>()
|
val translations = LinkedHashMap<String, String>()
|
||||||
val text = Gdx.files.internal(translationFile)
|
val text = Gdx.files.internal(translationFile)
|
||||||
text.reader(Charsets.UTF_8.toString()).forEachLine {
|
text.reader(charset).forEachLine { line ->
|
||||||
val line=it
|
|
||||||
if(!line.contains(" = ")) return@forEachLine
|
if(!line.contains(" = ")) return@forEachLine
|
||||||
val splitLine = line.split(" = ")
|
val splitLine = line.split(" = ")
|
||||||
if(splitLine[1]!="") { // the value is empty, this means this wasn't translated yet
|
if(splitLine[1]!="") { // the value is empty, this means this wasn't translated yet
|
||||||
@ -20,7 +24,7 @@ class TranslationFileReader{
|
|||||||
return translations
|
return translations
|
||||||
}
|
}
|
||||||
|
|
||||||
fun writeByTemplate(language:String, translations: HashMap<String, String>){
|
private fun writeByTemplate(language:String, translations: HashMap<String, String>){
|
||||||
val templateFile = Gdx.files.internal("jsons/translationsByLanguage/template.properties")
|
val templateFile = Gdx.files.internal("jsons/translationsByLanguage/template.properties")
|
||||||
val stringBuilder = StringBuilder()
|
val stringBuilder = StringBuilder()
|
||||||
for(line in templateFile.reader().readLines()){
|
for(line in templateFile.reader().readLines()){
|
||||||
@ -37,7 +41,7 @@ class TranslationFileReader{
|
|||||||
stringBuilder.appendln(lineToWrite)
|
stringBuilder.appendln(lineToWrite)
|
||||||
}
|
}
|
||||||
Gdx.files.local("jsons/translationsByLanguage/$language.properties")
|
Gdx.files.local("jsons/translationsByLanguage/$language.properties")
|
||||||
.writeString(stringBuilder.toString(),false,Charsets.UTF_8.name())
|
.writeString(stringBuilder.toString(),false,charset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -54,8 +58,7 @@ class TranslationFileReader{
|
|||||||
writeLanguagePercentages(translations)
|
writeLanguagePercentages(translations)
|
||||||
}
|
}
|
||||||
|
|
||||||
val percentagesFileLocation = "jsons/translationsByLanguage/completionPercentages.properties"
|
private fun writeLanguagePercentages(translations: Translations){
|
||||||
fun writeLanguagePercentages(translations: Translations){
|
|
||||||
val percentages = translations.calculatePercentageCompleteOfLanguages()
|
val percentages = translations.calculatePercentageCompleteOfLanguages()
|
||||||
val stringBuilder = StringBuilder()
|
val stringBuilder = StringBuilder()
|
||||||
for(entry in percentages){
|
for(entry in percentages){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user