Skip to content

Commit b0df27c

Browse files
committed
Added everything
1 parent b708b6b commit b0df27c

10 files changed

Lines changed: 177 additions & 12 deletions

File tree

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 TheSimpleTeam
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# LocalizationAPP
2+
Noa is lazy so he asked me an easy way to add localization keys

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ plugins {
33
id 'application'
44
id 'org.openjfx.javafxplugin' version '0.0.8'
55
}
6-
group = 'com.test'
6+
group = 'fr.minemobs'
77
version = '1.0-SNAPSHOT'
88

99
repositories {
1010
mavenCentral()
1111
}
1212

1313
application {
14-
mainClassName = "com.example.MainKt"
14+
mainClassName = "fr.minemobs.pepitedorlocalization.MainKt"
1515
}
1616

1717
dependencies {
1818
implementation "no.tornado:tornadofx:$tornadofx_version"
19+
implementation 'com.google.code.gson:gson:2.8.8'
20+
implementation "org.jetbrains.kotlin:kotlin-reflect:1.4.32"
1921
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
2022
}
2123

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package fr.minemobs.pepitedorlocalization
22

33
import fr.minemobs.pepitedorlocalization.view.MainView
4-
import tornadofx.App
4+
import tornadofx.*
55

66
class MyApp: App(MainView::class, Styles::class)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package fr.minemobs.pepitedorlocalization
2+
3+
import javafx.collections.ObservableList
4+
import tornadofx.*
5+
import java.io.File
6+
7+
class MyController : Controller() {
8+
9+
fun getAllLanguages(folder: File) : ObservableList<String> {
10+
if(folder.listFiles() == null) return observableListOf()
11+
val files : ObservableList<String> = observableListOf()
12+
for (file in folder.listFiles()!!.filter { f -> f.name.endsWith(".json") }) {
13+
files.add(file.nameWithoutExtension)
14+
}
15+
return files
16+
}
17+
18+
}
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
package fr.minemobs.pepitedorlocalization
22

3+
import javafx.scene.paint.Color
34
import javafx.scene.text.FontWeight
4-
import tornadofx.Stylesheet
5-
import tornadofx.box
6-
import tornadofx.cssclass
7-
import tornadofx.px
5+
import tornadofx.*
86

97
class Styles : Stylesheet() {
108
companion object {
119
val heading by cssclass()
1210
}
1311

1412
init {
13+
form {
14+
backgroundColor += c("#2E3244")
15+
}
1516
label and heading {
1617
padding = box(10.px)
1718
fontSize = 20.px
1819
fontWeight = FontWeight.BOLD
1920
}
21+
label {
22+
textFill = Color.ANTIQUEWHITE
23+
}
24+
textField {
25+
backgroundColor += c("#2B2B2B")
26+
textFill = Color.ANTIQUEWHITE
27+
}
28+
button {
29+
textFill = c("#F1895C")
30+
baseColor = c("#516079")
31+
}
32+
comboBox {
33+
textFill = c("#F1895C")
34+
baseColor = c("#516079")
35+
}
2036
}
2137
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fr.minemobs.pepitedorlocalization.event
2+
3+
import tornadofx.*
4+
5+
object OnDirectoryChoosed : FXEvent(EventBus.RunOn.ApplicationThread)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fr.minemobs.pepitedorlocalization.event
2+
3+
import tornadofx.*
4+
5+
object OnItemChoosed : FXEvent(EventBus.RunOn.ApplicationThread)
Lines changed: 101 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,108 @@
11
package fr.minemobs.pepitedorlocalization.view
22

3-
import fr.minemobs.pepitedorlocalization.Styles
3+
import com.google.gson.GsonBuilder
4+
import com.google.gson.stream.JsonReader
5+
import com.google.gson.stream.JsonWriter
6+
import fr.minemobs.pepitedorlocalization.MyController
7+
import fr.minemobs.pepitedorlocalization.event.OnDirectoryChoosed
8+
import javafx.beans.property.SimpleStringProperty
9+
import javafx.geometry.HPos
10+
import javafx.geometry.Orientation
11+
import javafx.geometry.VPos
12+
import javafx.scene.image.Image
413
import tornadofx.*
14+
import java.io.File
15+
import java.io.FileReader
16+
import java.io.FileWriter
17+
import java.nio.file.Files
18+
import java.nio.file.StandardOpenOption
19+
import java.util.*
20+
import kotlin.collections.HashMap
21+
import kotlin.collections.LinkedHashMap
522

6-
class MainView : View("Hello TornadoFX") {
7-
override val root = hbox {
8-
label(title) {
9-
addClass(Styles.heading)
23+
class MainView : View("Pepite D'or Localization UI") {
24+
25+
private val gson = GsonBuilder().setPrettyPrinting().serializeNulls().create()
26+
private val controller: MyController by inject()
27+
private var folderLoc: File? = null
28+
private val key = SimpleStringProperty()
29+
private var lang = SimpleStringProperty()
30+
private var translatedString = SimpleStringProperty()
31+
32+
override val root = form {
33+
fieldset {
34+
field("Localization directory") {
35+
button("Target Directory") {
36+
action {
37+
val dir = chooseDirectory("Select Target Directory") ?: return@action
38+
if(!dir.isDirectory) return@action
39+
folderLoc = dir
40+
fire(OnDirectoryChoosed)
41+
}
42+
}
43+
}
44+
45+
subscribe<OnDirectoryChoosed> {
46+
run {
47+
field("Languages", Orientation.HORIZONTAL, true) {
48+
combobox<String>(lang, controller.getAllLanguages(folderLoc!!))
49+
}
50+
}
51+
}
52+
}
53+
fieldset {
54+
field("Localization Key") {
55+
textfield(key)
56+
gridpaneConstraints {
57+
vAlignment = VPos.BOTTOM
58+
}
59+
}
60+
61+
var btn = button()
62+
btn.hide()
63+
64+
lang.onChangeOnce {
65+
field("Translated String") {
66+
textfield(translatedString)
67+
}
68+
}
69+
70+
lang.onChange {
71+
this.children.remove(btn)
72+
btn = button("Add to ${it!!}.json") {
73+
gridpaneConstraints {
74+
hAlignment = HPos.CENTER
75+
}
76+
action {
77+
if(key.value == null || key.value.isEmpty()) return@action
78+
val jsonFile = File(folderLoc!!, "$it.json")
79+
val reader = FileReader(jsonFile, Charsets.UTF_8)
80+
val map : HashMap<String, String> = LinkedHashMap()
81+
map.putAll(gson.fromJson(reader, map.javaClass))
82+
map[key.value] = translatedString.value
83+
val writer = FileWriter(jsonFile, Charsets.UTF_8)
84+
gson.toJson(map, writer)
85+
writer.close()
86+
println("Added \"${key.value}\": \"${translatedString.value}\"")
87+
}
88+
}
89+
}
1090
}
1191
}
92+
93+
override fun onBeforeShow() {
94+
setStageIcon(Image("icon.png"))
95+
96+
}
97+
98+
override fun onDock() {
99+
currentStage?.width = 400.0
100+
currentStage?.height = 300.0
101+
currentStage?.isResizable = false
102+
}
103+
104+
init {
105+
primaryStage.isAlwaysOnTop = true
106+
}
12107
}
108+

src/main/resources/icon.png

8.24 KB
Loading

0 commit comments

Comments
 (0)