mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-11 03:18:18 +07:00
IT IS DONE
Translations are now split by language, and new translations can be added to all languages by changing the templates.properties file!
This commit is contained in:
parent
b544615643
commit
04ad012cd9
@ -176,7 +176,7 @@
|
||||
name:"Theology",
|
||||
row:2,
|
||||
prerequisites:["Philosophy"],
|
||||
quote:"'Three things are necessary for the salvarion of man: to know what he ought to believe; to know what he ought to desire; and to know what he ought to do' - St. Thomas Aquinas"
|
||||
quote:"'Three things are necessary for the salvation of man: to know what he ought to believe; to know what he ought to desire; and to know what he ought to do' - St. Thomas Aquinas"
|
||||
},
|
||||
{
|
||||
name:"Civil Service",
|
||||
|
@ -541,7 +541,7 @@
|
||||
Korean:"신학"
|
||||
}
|
||||
|
||||
"'Three things are necessary for the salvarion of man: to know what he ought to believe; to know what he ought to desire; and to know what he ought to do' - St. Thomas Aquinas":{
|
||||
"'Three things are necessary for the salvation of man: to know what he ought to believe; to know what he ought to desire; and to know what he ought to do' - St. Thomas Aquinas":{
|
||||
Italian:"'Tre cose sono necessarie per la salvezza dell'uomo: sapere in cosa deve credere; sapere che cosa deve desiderare; sapere cosa deve fare.' - San Tommaso d'Aquino"
|
||||
Simplified_Chinese:"“有三点是自我救赎所必需的:知道自己应该信什么;知道自己应该要什么;知道自己应该做什么。”——圣托马斯·阿奎那"
|
||||
Traditional_Chinese:"“有三點是自我救贖所必須的:知道自己應該信什麼;知道自己應該要什麼;知道自己應該做什麼。”——聖湯碼士·阿奎那"
|
||||
|
1417
android/assets/jsons/translationsByLanguage/Czech.properties
Normal file
1417
android/assets/jsons/translationsByLanguage/Czech.properties
Normal file
File diff suppressed because it is too large
Load Diff
2431
android/assets/jsons/translationsByLanguage/Dutch.properties
Normal file
2431
android/assets/jsons/translationsByLanguage/Dutch.properties
Normal file
File diff suppressed because it is too large
Load Diff
2736
android/assets/jsons/translationsByLanguage/English.properties
Normal file
2736
android/assets/jsons/translationsByLanguage/English.properties
Normal file
File diff suppressed because it is too large
Load Diff
1458
android/assets/jsons/translationsByLanguage/French.properties
Normal file
1458
android/assets/jsons/translationsByLanguage/French.properties
Normal file
File diff suppressed because it is too large
Load Diff
1538
android/assets/jsons/translationsByLanguage/German.properties
Normal file
1538
android/assets/jsons/translationsByLanguage/German.properties
Normal file
File diff suppressed because it is too large
Load Diff
1398
android/assets/jsons/translationsByLanguage/Italian.properties
Normal file
1398
android/assets/jsons/translationsByLanguage/Italian.properties
Normal file
File diff suppressed because it is too large
Load Diff
1407
android/assets/jsons/translationsByLanguage/Korean.properties
Normal file
1407
android/assets/jsons/translationsByLanguage/Korean.properties
Normal file
File diff suppressed because it is too large
Load Diff
2547
android/assets/jsons/translationsByLanguage/Malay.properties
Normal file
2547
android/assets/jsons/translationsByLanguage/Malay.properties
Normal file
File diff suppressed because it is too large
Load Diff
2003
android/assets/jsons/translationsByLanguage/Polish.properties
Normal file
2003
android/assets/jsons/translationsByLanguage/Polish.properties
Normal file
File diff suppressed because it is too large
Load Diff
1657
android/assets/jsons/translationsByLanguage/Portuguese.properties
Normal file
1657
android/assets/jsons/translationsByLanguage/Portuguese.properties
Normal file
File diff suppressed because it is too large
Load Diff
2050
android/assets/jsons/translationsByLanguage/Romanian.properties
Normal file
2050
android/assets/jsons/translationsByLanguage/Romanian.properties
Normal file
File diff suppressed because it is too large
Load Diff
1472
android/assets/jsons/translationsByLanguage/Russian.properties
Normal file
1472
android/assets/jsons/translationsByLanguage/Russian.properties
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
2048
android/assets/jsons/translationsByLanguage/Spanish.properties
Normal file
2048
android/assets/jsons/translationsByLanguage/Spanish.properties
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1824
android/assets/jsons/translationsByLanguage/Ukrainian.properties
Normal file
1824
android/assets/jsons/translationsByLanguage/Ukrainian.properties
Normal file
File diff suppressed because it is too large
Load Diff
1398
android/assets/jsons/translationsByLanguage/templates.properties
Normal file
1398
android/assets/jsons/translationsByLanguage/templates.properties
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,9 @@ import com.unciv.models.ruleset.tile.TileResource
|
||||
import com.unciv.models.ruleset.unit.BaseUnit
|
||||
import com.unciv.models.ruleset.unit.Promotion
|
||||
import com.unciv.models.stats.INamed
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.LinkedHashMap
|
||||
import kotlin.collections.set
|
||||
|
||||
class Ruleset {
|
||||
@ -108,38 +111,65 @@ class Ruleset {
|
||||
// which means we need to list everything manually =/
|
||||
|
||||
val translationStart = System.currentTimeMillis()
|
||||
val translationFileNames = listOf("Buildings","Diplomacy,Trade,Nations",
|
||||
"NewGame,SaveGame,LoadGame,Options", "Notifications","Other","Policies","Techs",
|
||||
"Terrains,Resources,Improvements","Units,Promotions")
|
||||
|
||||
for (fileName in translationFileNames){
|
||||
val file = Gdx.files.internal("jsons/Translations/$fileName.json")
|
||||
if(file.exists()) {
|
||||
Translations.add(file.readString(Charsets.UTF_8.name()))
|
||||
}
|
||||
}
|
||||
|
||||
// for(language in Translations.getLanguages()){
|
||||
// val translationsOfLanguage = HashMap<String,String>()
|
||||
// val stringBuilder=StringBuilder()
|
||||
// for(translation in Translations.values) {
|
||||
//
|
||||
// stringBuilder.append(translation.entry)
|
||||
// stringBuilder.append('=')
|
||||
//
|
||||
//
|
||||
// if (translation.containsKey(language))
|
||||
// stringBuilder.append(translation[language]!!)
|
||||
// stringBuilder.appendln()
|
||||
// }
|
||||
//
|
||||
// val finalFile = stringBuilder.toString()
|
||||
// Gdx.files.local("jsons/Translations/$language.json")
|
||||
// .writeString(finalFile,false,Charsets.UTF_8.name())
|
||||
// }
|
||||
readTranslationsFromProperties()
|
||||
// readTranslationsFromJson()
|
||||
// writeNewTranslationFiles()
|
||||
|
||||
val translationFilesTime = System.currentTimeMillis() - translationStart
|
||||
println("Loading translation files - "+translationFilesTime+"ms")
|
||||
}
|
||||
|
||||
private fun writeNewTranslationFiles() {
|
||||
for (language in Translations.getLanguages()) {
|
||||
val languageHashmap = HashMap<String, String>()
|
||||
|
||||
for (translation in Translations.values) {
|
||||
if (translation.containsKey(language))
|
||||
languageHashmap[translation.entry] = translation[language]!!
|
||||
}
|
||||
TranslationFileReader().writeByTemplate(language, languageHashmap)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun readTranslationsFromProperties() {
|
||||
|
||||
val languages = ArrayList<String>()
|
||||
// languages.add("templates") // first off,
|
||||
languages.addAll(Locale.getAvailableLocales()
|
||||
.map { it.displayName })
|
||||
|
||||
// These should probably ve renamed
|
||||
languages.add("Simplified_Chinese")
|
||||
languages.add("Traditional_Chinese")
|
||||
|
||||
for (language in languages) {
|
||||
val translationFileName = "jsons/translationsByLanguage/$language.properties"
|
||||
if (!Gdx.files.internal(translationFileName).exists()) continue
|
||||
val languageTranslations = TranslationFileReader().read(translationFileName)
|
||||
|
||||
for (translation in languageTranslations) {
|
||||
if (!Translations.containsKey(translation.key))
|
||||
Translations[translation.key] = TranslationEntry(translation.key)
|
||||
Translations[translation.key]!![language] = translation.value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readTranslationsFromJson() {
|
||||
|
||||
val translationFileNames = listOf("Buildings","Diplomacy,Trade,Nations",
|
||||
"NewGame,SaveGame,LoadGame,Options", "Notifications","Other","Policies","Techs",
|
||||
"Terrains,Resources,Improvements","Units,Promotions")
|
||||
|
||||
for (fileName in translationFileNames) {
|
||||
val file = Gdx.files.internal("jsons/Translations/$fileName.json")
|
||||
if (file.exists()) {
|
||||
Translations.add(file.readString(Charsets.UTF_8.name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,21 @@
|
||||
package com.unciv.models.ruleset
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.utils.JsonReader
|
||||
import com.unciv.UncivGame
|
||||
import java.util.*
|
||||
|
||||
class TranslationEntry(val entry:String) : HashMap<String, String>(){
|
||||
class TranslationEntry(val entry: String) : HashMap<String, String>() {
|
||||
|
||||
/** For memory performance on .tr(), which was atrociously memory-expensive */
|
||||
var entryWithShortenedSquareBrackets =""
|
||||
|
||||
init {
|
||||
if(entry.contains('['))
|
||||
entryWithShortenedSquareBrackets=entry.replace(squareBraceRegex,"[]")
|
||||
}
|
||||
}
|
||||
|
||||
class Translations : HashMap<String, TranslationEntry>(){
|
||||
class Translations : LinkedHashMap<String, TranslationEntry>(){
|
||||
|
||||
fun add(json:String){
|
||||
val jsonValue = JsonReader().parse(json)!!
|
||||
@ -19,8 +25,6 @@ class Translations : HashMap<String, TranslationEntry>(){
|
||||
val currentEntryName = currentEntry.name!!
|
||||
val translationEntry = TranslationEntry(currentEntryName)
|
||||
this[currentEntryName]=translationEntry
|
||||
if(currentEntryName.contains('['))
|
||||
translationEntry.entryWithShortenedSquareBrackets=currentEntryName.replace(squareBraceRegex,"[]")
|
||||
|
||||
var currentLanguage = currentEntry.child
|
||||
while(currentLanguage!=null){
|
||||
@ -69,6 +73,42 @@ class Translations : HashMap<String, TranslationEntry>(){
|
||||
}
|
||||
}
|
||||
|
||||
class TranslationFileReader(){
|
||||
fun read(translationFile:String): LinkedHashMap<String, String> {
|
||||
val translations = LinkedHashMap<String,String>()
|
||||
val text = Gdx.files.internal(translationFile)
|
||||
for(line in text.reader().readLines()){
|
||||
if(!line.contains(" = ")) continue
|
||||
val splitLine = line.split(" = ")
|
||||
val key = splitLine[0].replace("\\n","\n")
|
||||
val value = splitLine[1].replace("\\n","\n")
|
||||
if(value!="") // this means this wasn't translated yet
|
||||
translations[key] = value
|
||||
}
|
||||
return translations
|
||||
}
|
||||
|
||||
fun writeByTemplate(language:String, translations: HashMap<String,String>){
|
||||
val templateFile = Gdx.files.internal("jsons/translationsByLanguage/templates.properties")
|
||||
val stringBuilder = StringBuilder()
|
||||
for(line in templateFile.reader().readLines()){
|
||||
if(!line.contains(" = ")){ // copy as-is
|
||||
stringBuilder.appendln(line)
|
||||
continue
|
||||
}
|
||||
val translationKey = line.split(" = ")[0].replace("\\n","\n")
|
||||
var translationValue = ""
|
||||
if(translations.containsKey(translationKey)) translationValue = translations[translationKey]!!
|
||||
else stringBuilder.appendln(" # Requires translation!")
|
||||
val lineToWrite = translationKey.replace("\n","\\n") +
|
||||
" = "+ translationValue.replace("\n","\\n")
|
||||
stringBuilder.appendln(lineToWrite)
|
||||
}
|
||||
Gdx.files.local("jsons/translationsByLanguage/$language.properties")
|
||||
.writeString(stringBuilder.toString(),false,Charsets.UTF_8.name())
|
||||
}
|
||||
}
|
||||
|
||||
val squareBraceRegex = Regex("\\[(.*?)\\]") // we don't need to allocate different memory for this every time we .tr()
|
||||
|
||||
val eitherSquareBraceRegex=Regex("\\[|\\]")
|
||||
|
Loading…
Reference in New Issue
Block a user