├── .github └── workflows │ ├── commitTest.yml │ └── prTest.yml ├── .gitignore ├── README.md ├── assets ├── bundles │ └── bundle.properties └── sprites │ └── logo.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── icon.png ├── mod.hjson ├── showcase ├── mindustry-auto-translation.gif └── settings.png └── src └── autotranslate └── AutoTranslate.java /.github/workflows/commitTest.yml: -------------------------------------------------------------------------------- 1 | name: Commit Testing 2 | 3 | on: [push] 4 | 5 | jobs: 6 | buildJar: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Set up PATH 12 | run: | 13 | echo "${ANDROID_HOME}/build-tools/30.0.1" >> $GITHUB_PATH 14 | - name: Set up JDK 17 15 | uses: actions/setup-java@v1 16 | with: 17 | java-version: 17 18 | - name: Build mod jar 19 | run: ./gradlew deploy 20 | - name: Upload built jar file 21 | uses: actions/upload-artifact@v2 22 | with: 23 | name: ${{ github.event.repository.name }} 24 | path: build/libs/${{ github.event.repository.name }}.jar 25 | -------------------------------------------------------------------------------- /.github/workflows/prTest.yml: -------------------------------------------------------------------------------- 1 | name: Pull Request Testing 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | buildJar: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Set up PATH 12 | run: | 13 | echo "${ANDROID_HOME}/build-tools/30.0.1" >> $GITHUB_PATH 14 | - name: Set up JDK 16 15 | uses: actions/setup-java@v1 16 | with: 17 | java-version: 16 18 | - name: Build mod jar 19 | run: ./gradlew deploy 20 | - name: Upload built jar file 21 | uses: actions/upload-artifact@v2 22 | with: 23 | name: ${{ github.event.repository.name }} Pull Request 24 | path: build/libs/${{ github.event.repository.name }}.jar 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | /core/assets/mindustry-saves/ 3 | /core/assets/mindustry-maps/ 4 | /core/assets/bundles/output/ 5 | /core/assets/.gifimages/ 6 | /deploy/ 7 | /desktop/packr-out/ 8 | /desktop/packr-export/ 9 | /desktop/mindustry-saves/ 10 | /desktop/mindustry-maps/ 11 | /desktop/gifexport/ 12 | /core/lib/ 13 | /ios/assets/ 14 | /core/assets-raw/sprites/generated/ 15 | /core/assets-raw/sprites_out/ 16 | /annotations/build/ 17 | /annotations/out/ 18 | /net/build/ 19 | /tools/build/ 20 | /tests/build/ 21 | /server/build/ 22 | /test_files/ 23 | /annotations/build/ 24 | /desktop-sdl/build/ 25 | desktop-sdl/build/ 26 | /android/assets/mindustry-maps/ 27 | /android/assets/mindustry-saves/ 28 | /core/assets/gifexport/ 29 | /core/assets/version.properties 30 | /core/assets/locales 31 | /ios/src/io/anuke/mindustry/gen/ 32 | /core/src/io/anuke/mindustry/gen/ 33 | ios/robovm.properties 34 | packr-out/ 35 | config/ 36 | run.bat 37 | 38 | version.properties 39 | 40 | .attach_* 41 | ## Java 42 | 43 | *.class 44 | *.war 45 | *.ear 46 | hs_err_pid* 47 | crash-report-* 48 | 49 | ## Robovm 50 | /ios/robovm-build/ 51 | 52 | ## GWT 53 | /html/war/ 54 | /html/gwt-unitCache/ 55 | .apt_generated/ 56 | .gwt/ 57 | gwt-unitCache/ 58 | www-test/ 59 | .gwt-tmp/ 60 | 61 | ## Android Studio and Intellij and Android in general 62 | /android/libs/armeabi/ 63 | /android/libs/armeabi-v7a/ 64 | /android/libs/arm64-v8a/ 65 | /android/libs/x86/ 66 | /android/libs/x86_64/ 67 | /android/gen/ 68 | .idea/ 69 | *.ipr 70 | *.iws 71 | *.iml 72 | /android/out/ 73 | com_crashlytics_export_strings.xml 74 | 75 | ## Eclipse 76 | 77 | .classpath 78 | .project 79 | .metadata/ 80 | /android/bin/ 81 | /core/bin/ 82 | /desktop/bin/ 83 | /html/bin/ 84 | /ios/bin/ 85 | /ios-moe/bin/ 86 | *.tmp 87 | *.bak 88 | *.swp 89 | *~.nib 90 | .settings/ 91 | .loadpath 92 | .externalToolBuilders/ 93 | *.launch 94 | 95 | ## NetBeans 96 | 97 | /nbproject/private/ 98 | /android/nbproject/private/ 99 | /core/nbproject/private/ 100 | /desktop/nbproject/private/ 101 | /html/nbproject/private/ 102 | /ios/nbproject/private/ 103 | /ios-moe/nbproject/private/ 104 | 105 | /build/ 106 | /android/build/ 107 | /core/build/ 108 | /desktop/build/ 109 | /html/build/ 110 | /ios/build/ 111 | /ios-moe/build/ 112 | 113 | /nbbuild/ 114 | /android/nbbuild/ 115 | /core/nbbuild/ 116 | /desktop/nbbuild/ 117 | /html/nbbuild/ 118 | /ios/nbbuild/ 119 | /ios-moe/nbbuild/ 120 | 121 | /dist/ 122 | /android/dist/ 123 | /core/dist/ 124 | /desktop/dist/ 125 | /html/dist/ 126 | /ios/dist/ 127 | /ios-moe/dist/ 128 | 129 | /nbdist/ 130 | /android/nbdist/ 131 | /core/nbdist/ 132 | /desktop/nbdist/ 133 | /html/nbdist/ 134 | /ios/nbdist/ 135 | /ios-moe/nbdist/ 136 | 137 | nbactions.xml 138 | nb-configuration.xml 139 | 140 | ## Gradle 141 | 142 | /local.properties 143 | .gradle/ 144 | gradle-app.setting 145 | /build/ 146 | /android/build/ 147 | /core/build/ 148 | /desktop/build/ 149 | /html/build/ 150 | /ios/build/ 151 | /ios-moe/build/ 152 | 153 | ## OS Specific 154 | .DS_Store 155 | Thumbs.db 156 | android/libs/ 157 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Auto Translate 2 | 3 | ![GitHub all releases](https://img.shields.io/github/downloads/Pointifix/AutoTranslate/total) 4 | ![GitHub Repo stars](https://img.shields.io/github/stars/Pointifix/AutoTranslate?style=social) 5 | 6 | Automatically translates chat messages in Mindustry multiplayer. 7 | 8 | Requires you to register an account at [Deepl](https://www.deepl.com/de/pro-checkout/account?productId=1200&yearly=false&trial=false). \ 9 | You will need to enter a credit card for verification, no money is being charge for the Deepl Api Free. 10 | The API includes 500.000 characters/month, which are approximately 10.000 messages/month, which should be more than enough 11 | for a single user. 12 | 13 | Further, if you are on a desktop, you need to change the modules file of your Mindustry jre to a modules file including the modules 14 | `jdk.crypto.ec jdk.crypto.cryptoki`. Otherwise, the mod is not able to establish a connection to Deepl. 15 | A modules file containing those two modules is available for download in the Releases. 16 | 17 | After registration copy your API Key found in your account settings and enter it into the settings of the mod. 18 | 19 | ![showcase](showcase/mindustry-auto-translation.gif "Showcase") 20 | 21 | Besides entering your API Key you can also change the language you want the messages to get translated to 22 | and disable/enable the mod while playing. 23 | 24 | ![settings](showcase/settings.png "Settings") 25 | -------------------------------------------------------------------------------- /assets/bundles/bundle.properties: -------------------------------------------------------------------------------- 1 | auto-translate.settings.title=Auto Translate 2 | auto-translate.settings.auth-key=Deepl Authentication Key 3 | auto-translate.settings.enabled=Enable/Disable Auto Translation 4 | auto-translate.settings.target-language=Target Language -------------------------------------------------------------------------------- /assets/sprites/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pointifix/AutoTranslate/a51670759701d13a4a55eaa4fdfd44b523c980ab/assets/sprites/logo.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "java" 2 | 3 | version '1.0' 4 | 5 | targetCompatibility = 8 6 | sourceCompatibility = JavaVersion.VERSION_16 7 | 8 | sourceSets.main.java.srcDirs = ["src"] 9 | 10 | repositories{ 11 | mavenCentral() 12 | maven{ url 'https://www.jitpack.io' } 13 | } 14 | 15 | ext{ 16 | //the build number that this mod is made for 17 | mindustryVersion = 'v144.3' 18 | jabelVersion = "93fde537c7" 19 | sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT") 20 | } 21 | 22 | //java 8 backwards compatibility flag 23 | allprojects{ 24 | tasks.withType(JavaCompile){ 25 | options.compilerArgs.addAll(['--release', '8']) 26 | } 27 | } 28 | 29 | dependencies{ 30 | implementation 'org.jetbrains:annotations:20.1.0' 31 | compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion" 32 | compileOnly "com.github.Anuken.MindustryJitpack:core:$mindustryVersion" 33 | 34 | annotationProcessor "com.github.Anuken:jabel:$jabelVersion" 35 | implementation 'com.deepl.api:deepl-java:0.2.1' 36 | } 37 | 38 | task jarAndroid{ 39 | dependsOn "jar" 40 | 41 | doLast{ 42 | if(!sdkRoot || !new File(sdkRoot).exists()) throw new GradleException("No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory."); 43 | 44 | def platformRoot = new File("$sdkRoot/platforms/").listFiles().sort().reverse().find{ f -> new File(f, "android.jar").exists()} 45 | 46 | if(!platformRoot) throw new GradleException("No android.jar found. Ensure that you have an Android platform installed.") 47 | 48 | //collect dependencies needed for desugaring 49 | def dependencies = (configurations.compileClasspath.asList() + configurations.runtimeClasspath.asList() + [new File(platformRoot, "android.jar")]).collect{ "--classpath $it.path" }.join(" ") 50 | 51 | //dex and desugar files - this requires d8 in your PATH 52 | "d8 $dependencies --min-api 14 --output ${project.archivesBaseName}Android.jar ${project.archivesBaseName}Desktop.jar" 53 | .execute(null, new File("$buildDir/libs")).waitForProcessOutput(System.out, System.err) 54 | } 55 | } 56 | 57 | jar{ 58 | archiveFileName = "${project.archivesBaseName}Desktop.jar" 59 | 60 | from{ 61 | configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it) } 62 | } 63 | 64 | from(rootDir){ 65 | include "mod.hjson" 66 | } 67 | 68 | from("assets/"){ 69 | include "**" 70 | } 71 | 72 | duplicatesStrategy = DuplicatesStrategy.EXCLUDE 73 | } 74 | 75 | task deploy(type: Jar){ 76 | dependsOn jarAndroid 77 | dependsOn jar 78 | archiveFileName = "${project.archivesBaseName}.jar" 79 | 80 | from{ [zipTree("$buildDir/libs/${project.archivesBaseName}Desktop.jar"), zipTree("$buildDir/libs/${project.archivesBaseName}Android.jar")] } 81 | 82 | doLast{ 83 | delete{ 84 | delete "$buildDir/libs/${project.archivesBaseName}Desktop.jar" 85 | delete "$buildDir/libs/${project.archivesBaseName}Android.jar" 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.jvmargs=--illegal-access=permit \ 2 | --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ 3 | --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \ 4 | --add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \ 5 | --add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \ 6 | --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ 7 | --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ 8 | --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ 9 | --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ 10 | --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \ 11 | --add-exports=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED \ 12 | --add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \ 13 | --add-exports=java.base/sun.reflect.annotation=ALL-UNNAMED -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pointifix/AutoTranslate/a51670759701d13a4a55eaa4fdfd44b523c980ab/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pointifix/AutoTranslate/a51670759701d13a4a55eaa4fdfd44b523c980ab/icon.png -------------------------------------------------------------------------------- /mod.hjson: -------------------------------------------------------------------------------- 1 | displayName: "AutoTranslate" 2 | name: "auto-translate" 3 | author: "Pointifix" 4 | main: "autotranslate.AutoTranslate" 5 | description: "Automatically translates chat messages" 6 | version: 1.0 7 | minGameVersion: 136 8 | java: true 9 | hidden: true 10 | -------------------------------------------------------------------------------- /showcase/mindustry-auto-translation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pointifix/AutoTranslate/a51670759701d13a4a55eaa4fdfd44b523c980ab/showcase/mindustry-auto-translation.gif -------------------------------------------------------------------------------- /showcase/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pointifix/AutoTranslate/a51670759701d13a4a55eaa4fdfd44b523c980ab/showcase/settings.png -------------------------------------------------------------------------------- /src/autotranslate/AutoTranslate.java: -------------------------------------------------------------------------------- 1 | package autotranslate; 2 | 3 | import arc.Core; 4 | import arc.Events; 5 | import arc.func.Cons; 6 | import arc.scene.event.*; 7 | import arc.scene.style.TextureRegionDrawable; 8 | import arc.scene.ui.Button; 9 | import arc.scene.ui.TextButton; 10 | import arc.struct.Seq; 11 | import arc.util.*; 12 | import com.deepl.api.*; 13 | import mindustry.Vars; 14 | import mindustry.game.EventType; 15 | import mindustry.gen.Call; 16 | import mindustry.mod.Mod; 17 | import mindustry.ui.dialogs.FullTextDialog; 18 | import mindustry.ui.dialogs.SettingsMenuDialog; 19 | import mindustry.ui.fragments.ChatFragment; 20 | 21 | import java.lang.reflect.Field; 22 | import java.util.concurrent.atomic.AtomicReference; 23 | 24 | import static arc.Core.bundle; 25 | import static mindustry.Vars.ui; 26 | 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | public class AutoTranslate extends Mod { 31 | String lastMessage = ""; 32 | 33 | String authKey; 34 | 35 | private Map messageCache = new HashMap(); 36 | 37 | @Override 38 | public void init() { 39 | Cons builder = settingsTable -> { 40 | AtomicReference authKey = new AtomicReference<>(Core.settings.getString("auth-key", "")); 41 | AtomicReference targetLanguage = new AtomicReference<>(Core.settings.getString("target-language", "en-GB")); 42 | 43 | SettingsMenuDialog.SettingsTable settings = new SettingsMenuDialog.SettingsTable(); 44 | settings.areaTextPref(bundle.get("auto-translate.settings.auth-key"), "", authKey::set); 45 | settings.textPref(bundle.get("auto-translate.settings.target-language"), "en-GB", targetLanguage::set); 46 | 47 | settings.pref(new ButtonSetting("Save", () -> { 48 | try { 49 | Translator translator = new Translator(authKey.get()); 50 | 51 | if (translator.getTargetLanguages().stream().anyMatch(l -> l.getCode().equals(targetLanguage.get()))) { 52 | this.authKey = authKey.get(); 53 | Core.settings.put("auth-key", this.authKey); 54 | Core.settings.put("target-language", targetLanguage.get()); 55 | 56 | showDialog("Auto Translation", "Successfully configured Auto Translate"); 57 | } else { 58 | StringBuilder languages = new StringBuilder("Available languages (enter language code):\n\n"); 59 | 60 | for (Language l : translator.getTargetLanguages()) { 61 | languages.append(l.getName()).append(" - ").append(l.getCode()).append("\n"); 62 | } 63 | 64 | showDialog("Error", languages.toString()); 65 | } 66 | } catch (IllegalArgumentException | DeepLException | InterruptedException e) { 67 | showDialog("Error", "Something went wrong: " + e.getMessage()); 68 | Log.err("Auto Translate: " + e.getMessage()); 69 | } 70 | })); 71 | 72 | settings.checkPref(bundle.get("auto-translate.settings.enabled"), true, e -> Core.settings.put("auto-translate-enabled", e)); 73 | 74 | settingsTable.add(settings); 75 | }; 76 | ui.settings.getCategories().add(new SettingsMenuDialog.SettingsCategory(bundle.get("auto-translate.settings.title"), new TextureRegionDrawable(Core.atlas.find("auto-translate-logo")), builder)); 77 | 78 | authKey = Core.settings.getString("auth-key", ""); 79 | 80 | if (authKey.isEmpty()) { 81 | showDialog("Auto Translate", "Failed to initialize, invalid or empty authentication key, go to settings and enter a valid Deepl authentication key"); 82 | } 83 | 84 | Events.on(EventType.PlayerChatEvent.class, e -> { 85 | String newMessage = Strings.stripColors(e.message).trim(); 86 | 87 | if (Core.settings.getBool("auto-translate-enabled", true)) { 88 | if (newMessage.isEmpty()) 89 | return; 90 | 91 | if(e.player != null && Vars.player != null) 92 | if(Vars.player.id == e.player.id) 93 | return; 94 | 95 | if (newMessage.contains("]")) newMessage = newMessage.substring(newMessage.indexOf("]")); 96 | 97 | if(newMessage.startsWith("+")) 98 | return; 99 | 100 | if(lastMessage.equals(newMessage)) 101 | return; 102 | 103 | String finalMessage = newMessage; 104 | lastMessage = newMessage; 105 | 106 | Threads.thread(() -> { 107 | try { 108 | Translator translator = new Translator(authKey); 109 | String language = Core.settings.getString("target-language", "en-GB"); 110 | 111 | TextResult translatedMessage = translateString(translator, language, finalMessage); 112 | 113 | if(translatedMessage == null) 114 | { 115 | Log.err("Failed to translate message: translatedMessage == null"); 116 | Vars.player.sendMessage("[red]Failed to translate message"); 117 | return; 118 | } 119 | 120 | String translation = translatedMessage.getText().trim() + " [lightgray] (" + translatedMessage.getDetectedSourceLanguage() + ")"; 121 | 122 | if(e.player != null) 123 | translation = "["+ Strings.stripColors(e.player.name()) +"]: " + translatedMessage.getText().trim() + " [lightgray] (" + translatedMessage.getDetectedSourceLanguage() + ")"; 124 | 125 | Vars.player.sendMessage(translation); 126 | } catch (DeepLException | InterruptedException error) { 127 | Log.err("Failed to translate message: " + error.getMessage()); 128 | Vars.player.sendMessage("[red]Failed to translate message"); 129 | } 130 | }); 131 | } 132 | }); 133 | } 134 | 135 | 136 | private void showDialog(String title, String message) { 137 | FullTextDialog baseDialog = new FullTextDialog(); 138 | 139 | baseDialog.show(title, message); 140 | } 141 | 142 | private class ButtonSetting extends SettingsMenuDialog.SettingsTable.Setting { 143 | String name; 144 | Runnable clicked; 145 | 146 | public ButtonSetting(String name, Runnable clicked) { 147 | super(name); 148 | this.name = name; 149 | this.clicked = clicked; 150 | } 151 | 152 | @Override 153 | public void add(SettingsMenuDialog.SettingsTable table) { 154 | table.button(name, clicked).margin(14).width(240f).pad(6); 155 | table.row(); 156 | } 157 | 158 | 159 | } 160 | 161 | private String getMD5FromString(String text) { 162 | try { 163 | java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); 164 | byte[] array = md.digest(text.getBytes()); 165 | StringBuffer sb = new StringBuffer(); 166 | for (int i = 0; i < array.length; ++i) { 167 | sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3)); 168 | } 169 | return sb.toString(); 170 | } catch (java.security.NoSuchAlgorithmException e) { 171 | } 172 | return null; 173 | } 174 | 175 | private TextResult translateString(Translator translator, String language, String finalMessage) throws DeepLException, InterruptedException { 176 | String messageKey = getMD5FromString(language + finalMessage); 177 | if(messageCache.containsKey(messageKey)) 178 | return messageCache.get(messageKey); 179 | 180 | TextResult result = translator.translateText(finalMessage, null, language); 181 | if (result.getDetectedSourceLanguage().equals(LanguageCode.standardize(language))) 182 | return null; 183 | 184 | messageCache.put(messageKey, result); 185 | return result; 186 | } 187 | } 188 | --------------------------------------------------------------------------------