Skip to content

Commit 2ccc0da

Browse files
author
Francisco Solis
committed
Added auto colorization of the translation
* Now translations are automatically colorized (unless you set `colorize` to `false`)
1 parent a268845 commit 2ccc0da

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v0.1.5 - Snapshot
2+
* Now translations are automatically colorized (unless you set `colorize` to `false`)
3+
14
# v0.1.4 - Snapshot
25
* Updated SimpleCoreAPI to v0.3.0-SNAPSHOT
36
* Now the TranslationManager is initialized at the load stage of the

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
id 'org.jetbrains.dokka' version '1.6.10'
88
}
99

10-
def projectVersion = (System.getenv("VERSION") ?: '0.1.4-SNAPSHOT').replaceFirst("v", "").replace('/', '')
10+
def projectVersion = (System.getenv("VERSION") ?: '0.1.5-SNAPSHOT').replaceFirst("v", "").replace('/', '')
1111

1212
group 'xyz.theprogramsrc'
1313
version projectVersion
@@ -31,7 +31,7 @@ dependencies {
3131
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.6.10'
3232
compileOnly 'org.spigotmc:spigot-api:1.18.1-R0.1-SNAPSHOT'
3333
compileOnly 'net.md-5:bungeecord-api:1.18-R0.1-SNAPSHOT'
34-
compileOnly 'xyz.theprogramsrc:simplecoreapi:0.3.0-SNAPSHOT'
34+
compileOnly 'xyz.theprogramsrc:simplecoreapi:0.3.1-SNAPSHOT'
3535
compileOnly 'xyz.theprogramsrc:filesmodule:0.1.1-SNAPSHOT'
3636

3737
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'

src/main/kotlin/xyz/theprogramsrc/translationsmodule/Translation.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ data class Translation(
3737
* You can use '{}' or '%%' as placeholder identifiers like '{test}' or '%test%'. Defaults to empty map.
3838
* @return The translated string.
3939
*/
40-
fun translate(language: String? = null, placeholders: Map<String, String> = emptyMap()): String {
40+
fun translate(language: String? = null, placeholders: Map<String, String> = emptyMap(), colorize: Boolean = true): String {
4141
val file = YmlConfig(File(File("translations/${if(group.endsWith("/")) group else "$group/"}").folder(), (language ?: TranslationManager.getCurrentLanguage()) + ".lang")) // Get the file of the translation
4242
val mainColor = this.mainColor ?: "" // Get the main color of the translation
4343
var translation = mainColor.plus(
@@ -59,7 +59,11 @@ data class Translation(
5959
translation = translation.replace("{$key}", value).replace("%$key%", value) // Replace the placeholder using %% and {}
6060
}
6161

62-
return translation // Return the translated string
62+
return if(colorize) { // Return the translated string
63+
translation.replace("&", "§")
64+
} else {
65+
translation
66+
}
6367
}
6468

6569
override fun equals(other: Any?): Boolean {

0 commit comments

Comments
 (0)