Skip to content

Commit

Permalink
Added number of same translations (possible not translated)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkienl committed Dec 27, 2022
1 parent 43010c6 commit f43ca6a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
70 changes: 58 additions & 12 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ fun startMenu() {
${s("[cli]Menu:")}
0) ${s("[cli]Exit")}
1) ${s("[cli]Check for missing keys")}
2) ${s("[cli]Check app settings")}
3) ${s("[cli]Edit app settings")}
2) ${s("[cli]Check for non-translated keys")}
3) ${s("[cli]Check app settings")}
4) ${s("[cli]Edit app settings")}
""".trimIndent()
)
val input = readln()
if (input.toIntOrNull() != null) {
when (input.toInt()) {
0 -> exitProcess(0)
1 -> checkForMissingKeys()
2 -> checkAppSettings()
3 -> editAppSettings()
2 -> checkForNonTranslatedKeys()
3 -> checkAppSettings()
4 -> editAppSettings()
else -> println(s("[cli]Number not found"))
}
}
Expand Down Expand Up @@ -95,34 +97,49 @@ fun askSubFolder(): String {
return input
}

fun checkForMissingKeys() {
/**
* Returns true when all is well
*/
fun checkSettings(): Boolean {
if (rootFolder == null) {
rootFolder = askRootFolder() ?: return
rootFolder = askRootFolder() ?: return false
}
val safeRootFolder = rootFolder ?: return
val safeRootFolder = rootFolder ?: return false
println(String.format(s("[cli]Set as root folder: %s"), safeRootFolder.absolutePath))
Util.getPreferences().put(AppPreferences.ROOT_FOLDER, safeRootFolder.absolutePath)

if (subFolder == null) {
subFolder = askSubFolder()
}
val safeSubFolder = subFolder ?: return
val safeSubFolder = subFolder ?: return false
println(String.format(s("[cli]Set as sub folder: %s"), safeRootFolder))
Util.getPreferences().put(AppPreferences.SUB_FOLDER, safeSubFolder)

if (sourceLangCode == null) {
sourceLangCode = askLangCode(s("[cli]Please enter source language (as language code, e.g. 'en')")) ?: return
sourceLangCode = askLangCode(s("[cli]Please enter source language (as language code, e.g. 'en')")) ?: return false
}
val safeSourceLangCode = sourceLangCode ?: return
val safeSourceLangCode = sourceLangCode ?: return false
Util.getPreferences().put(AppPreferences.SOURCE_LANG_CODE, safeSourceLangCode)

if (targetLangCode == null) {
targetLangCode = askLangCode(s("[cli]Please enter target language (as language code, e.g. 'nl')")) ?: return
targetLangCode = askLangCode(s("[cli]Please enter target language (as language code, e.g. 'nl')")) ?: return false
}
val safeTargetLangCode = targetLangCode ?: return
val safeTargetLangCode = targetLangCode ?: return false
Util.getPreferences().put(AppPreferences.TARGET_LANG_CODE, safeTargetLangCode)

return true
}

fun checkForMissingKeys() {
if (!checkSettings()) {
return
}
val safeRootFolder = rootFolder ?: return
val safeSubFolder = subFolder ?: return
val safeSourceLangCode = sourceLangCode ?: return
val safeTargetLangCode = targetLangCode ?: return

//
val sourceStrings = Util.loadTranslationStrings(safeRootFolder, safeSubFolder, safeSourceLangCode)
val targetStrings = Util.loadTranslationStrings(safeRootFolder, safeSubFolder, safeTargetLangCode)

Expand Down Expand Up @@ -155,6 +172,34 @@ fun checkForMissingKeys() {
println(String.format(s("[cli]Total strings: %s"), sourceStrings.size))
}

private fun checkForNonTranslatedKeys() {
if (!checkSettings()) {
return
}
val safeRootFolder = rootFolder ?: return
val safeSubFolder = subFolder ?: return
val safeSourceLangCode = sourceLangCode ?: return
val safeTargetLangCode = targetLangCode ?: return

val sourceStrings = Util.loadTranslationStrings(safeRootFolder, safeSubFolder, safeSourceLangCode)
val targetStrings = Util.loadTranslationStrings(safeRootFolder, safeSubFolder, safeTargetLangCode)

var sameTranslations = 0
println(s("[cli]Translations that are the same (possibly not translated):"))
sourceStrings.forEach { sourceString ->
//ignore translations that consists only out of numbers (e.g. "Dance_Double=8")
if ("\\d+".toRegex().matches(sourceString.translation)) {
return@forEach
}
val targetString = targetStrings.firstOrNull { it.key == sourceString.key } ?: return@forEach
if (sourceString.translation == targetString.translation) {
println("L${sourceString.linenumber} [${sourceString.section}] ${sourceString.key}=${sourceString.translation}")
sameTranslations++
}
}
println(String.format(s("[cli]Number of same translations: %s"), sameTranslations))
}

private fun checkAppSettings() {
val prefs = Util.getPreferences()
println(
Expand Down Expand Up @@ -186,6 +231,7 @@ private fun editAppSettings() {
0 -> {
return
}

1 -> {
rootFolder = askRootFolder()
rootFolder?.let { safeRootFolder ->
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Menu:=Menu:
Exit=Exit
Cancel=Cancel
Check for missing keys=Check for missing keys
Check for non-translated keys=Check for non-translated keys
Check app settings=Check app settings
Edit app settings=Edit app settings
Number not found=Number not found
Expand All @@ -25,3 +26,5 @@ Checking for missing keys...=Checking for missing keys...
No missing strings=No missing strings
Done. Missing %s: %d; Missing %s: %d=Done. Missing %s: %d; Missing %s: %d
Total strings: %s=Total strings: %s
Translations that are the same (possibly not translated):=Translations that are the same (possibly not translated):
Number of same translations: %s=Number of same translations: %s
5 changes: 4 additions & 1 deletion src/main/resources/nl.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Menu:=Menu:
Exit=Afsluiten
Cancel=Annuleren
Check for missing keys=Controleer op ontbrekende vertalingen (keys)
Check for missing keys=Controleer op niet-vertaalde vertalingen (keys)
Check app settings=Bekijk app instellingen
Edit app settings=Instellingen aanpassen
Number not found=Nummer niet gevonden
Expand All @@ -24,4 +25,6 @@ Checking for missing keys...=Controleren op ontbrekende vertalingen...
%s strings missing in the %s strings: ='%s' vertalingen die missen in '%s':
No missing strings=Er zijn geen missende vertalingen
Done. Missing %s: %d; Missing %s: %d=Klaar. Aantal missende '%s': %d; Aantal missende '%s': %d
Total strings: %s=Totaal aantal vertalingen: %s
Total strings: %s=Totaal aantal vertalingen: %s
Translations that are the same (possibly not translated):=Vertalingen die hetzelfde zijn (mogelijk nog niet vertaald):
Number of same translations: %s=Aantal vertalen die hetzelfde zijn: %s

0 comments on commit f43ca6a

Please sign in to comment.