mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 05:52:47 +00:00
add list of known dictionaries for more convenient links
This commit is contained in:
parent
b1eb33f6e2
commit
fd95b4dc87
10 changed files with 215 additions and 3 deletions
5
tools/make-dict-list/README.md
Normal file
5
tools/make-dict-list/README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# make-dict-list
|
||||
|
||||
This module takes care of generating a list of dictionaries available in the [dictionaries repository](https://codeberg.org/Helium314/aosp-dictionaries) for convenient linking when adding dictionaries in HeliBoard.
|
||||
|
||||
To use it, simply run `./gradlew tools:make-dict-list:makeDictList`
|
18
tools/make-dict-list/build.gradle
Normal file
18
tools/make-dict-list/build.gradle
Normal file
|
@ -0,0 +1,18 @@
|
|||
apply plugin: "java"
|
||||
apply plugin: 'kotlin'
|
||||
|
||||
ext {
|
||||
javaMainClass = "tools.dict.MakeDictList"
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
tasks.register('makeDictList', JavaExec) {
|
||||
args project.rootProject.project('app').projectDir.path + File.separator + 'src' +
|
||||
File.separator + 'main' + File.separator + 'assets'
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
main = javaMainClass
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package tools.dict
|
||||
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
|
||||
class MakeDictList {
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic fun main(args: Array<String>) {
|
||||
val readmeUrl = "https://codeberg.org/Helium314/aosp-dictionaries/raw/branch/main/README.md"
|
||||
val readmeText = URL(readmeUrl).readText()
|
||||
val fileText = doIt(readmeText)
|
||||
val targetDir = args[0]
|
||||
|
||||
File(targetDir).mkdirs()
|
||||
File("$targetDir/dictionaries_in_dict_repo.csv").writeText(fileText)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* extract dictionary list from README.md
|
||||
* output format: <localeString>,<type>,<experimental>
|
||||
* <experimental> is empty if dictionary is not experimental, no other check done
|
||||
* requires README.md to have dicts in correct "# Dictionaries" or "# Experimental dictionaries" sections
|
||||
*/
|
||||
private fun doIt(readme: String): String {
|
||||
// output format: <localeString>,<type>,<experimental>
|
||||
// experimental is empty if dictionary is not experimental, no other check done
|
||||
var mode = MODE_NOTHING
|
||||
val outLines = mutableListOf<String>()
|
||||
readme.split("\n").forEach { line ->
|
||||
if (line.startsWith("#")) {
|
||||
mode = if (line.trim() == "# Dictionaries")
|
||||
MODE_NORMAL
|
||||
else if (line.trim() == "# Experimental dictionaries")
|
||||
MODE_EXPERIMENTAL
|
||||
else
|
||||
MODE_NOTHING
|
||||
return@forEach
|
||||
}
|
||||
if (mode == MODE_NOTHING || !line.startsWith("*")) return@forEach
|
||||
val dictName = line.substringAfter("]").substringAfter("(").substringBefore(")")
|
||||
.substringAfterLast("/").substringBefore(".dict")
|
||||
val type = dictName.substringBefore("_")
|
||||
val rawLocale = dictName.substringAfter("_")
|
||||
val locale = if ("_" !in rawLocale) rawLocale
|
||||
else {
|
||||
val split = rawLocale.split("_").toMutableList()
|
||||
if (!split[1].startsWith("#"))
|
||||
split[1] = split[1].uppercase()
|
||||
split.joinToString("_")
|
||||
}
|
||||
outLines.add("$type,$locale,${if (mode == MODE_EXPERIMENTAL) "exp" else ""}")
|
||||
}
|
||||
return outLines.joinToString("\n") + "\n"
|
||||
}
|
||||
|
||||
private const val MODE_NOTHING = 0
|
||||
private const val MODE_NORMAL = 1
|
||||
private const val MODE_EXPERIMENTAL = 2
|
Loading…
Add table
Add a link
Reference in a new issue