├── .github └── FUNDING.yml ├── .gitignore ├── .idea ├── .gitignore ├── artifacts │ └── String_Translator_App_jvm.xml ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── kotlinc.xml ├── misc.xml ├── runConfigurations │ └── desktop.xml └── vcs.xml ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── image ├── StringTranslatorDesktopApp.png ├── s0.png ├── s1.png ├── s10.png ├── s11.png ├── s12.png ├── s13.png ├── s2.png ├── s3.png ├── s4.png ├── s5.png ├── s6.png ├── s7.png ├── s8.png └── s9.png ├── local.properties ├── settings.gradle.kts ├── src └── main │ ├── kotlin │ ├── App.kt │ ├── Main.kt │ ├── models │ │ ├── Language.kt │ │ └── StringModel.kt │ ├── screen │ │ ├── Components.kt │ │ ├── SelectCountryScreen.kt │ │ └── TranslateScreen.kt │ ├── theme │ │ └── Color.kt │ ├── translate │ │ └── TranslationConnection.kt │ └── utils │ │ ├── Contant.kt │ │ └── StringConvertUtil.kt │ └── resources │ └── translate.svg ├── translate.icns ├── translate.ico └── translate.png /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | buy_me_a_coffee: codingmeet 2 | # # These are supported funding model platforms 3 | 4 | # github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 5 | # patreon: # Replace with a single Patreon username 6 | # open_collective: # Replace with a single Open Collective username 7 | # ko_fi: # Replace with a single Ko-fi username 8 | # tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 9 | # community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 10 | # liberapay: # Replace with a single Liberapay username 11 | # issuehunt: # Replace with a single IssueHunt username 12 | # lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | # polar: # Replace with a single Polar username 14 | # buy_me_a_coffee: # Replace with a single Buy Me a Coffee username 15 | # thanks_dev: # Replace with a single thanks.dev username 16 | # custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | /.gradle/ 3 | /build/ 4 | /build/classes/ 5 | /build/classes/kotlin/main/ -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/artifacts/String_Translator_App_jvm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/build/libs 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | 34 | 35 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations/desktop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 16 | 18 | true 19 | true 20 | false 21 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Meet 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![String Translator Desktop App Preview](image/StringTranslatorDesktopApp.png)](https://www.youtube.com/watch?v=EDbxJkgJDf8) 2 | 3 | Click the image above to watch a demo of the String Translator Desktop App on YouTube. 4 | 5 | ## Overview 6 | 7 | String Translator Desktop App is a powerful desktop application built with Jetpack Compose, aiming to streamline the translation of strings for developers. It empowers users to seamlessly translate multiple strings into various languages, thereby optimizing the localization process. 8 | 9 | ## Features 10 | 11 | - **Bulk Translation**: Translate multiple strings at once to target languages. 12 | - **Language Selection**: Choose from a variety of supported languages for translation. 13 | - **Jetpack Compose UI**: Enjoy an intuitive and visually appealing interface built with Jetpack Compose. 14 | - **Translation with Google Translate**: Effortlessly translate your text using Google Translate without the need for an API key. 15 | - **Export to XML Format**: Export translated strings to XML for seamless integration into your projects. 16 | 17 | ## Getting Started 18 | 19 | ### How to Build and Run the App 🛠️ 20 | 21 | 1. Clone the repository: `https://github.com/Coding-Meet/String-Translator-App.git` 22 | 2. Navigate to the project directory: `cd String-Translator-App` 23 | 3. Build the project: `./gradlew build` 24 | 4. Run the application: `./gradlew run` 25 | 26 | ## Working 💻 27 | 28 | 1. **Launch the application.** 29 | 30 | ![Step 1](image/s1.png) 31 | 32 | 2. **Enter the source strings in XML format into the provided text field.** 33 | 34 | ![Step 2](image/s0.png) 35 | ![Step 3](image/s2.png) 36 | 37 | 3. **Select the target languages.** 38 | 39 | ![Step 4](image/s3.png) 40 | 41 | 4. **Enter the folder name where you want to store the translated strings.** 42 | 43 | ![Step 5](image/s4.png) 44 | 45 | 5. **Click "Translate" to initiate the translation process.** 46 | 47 | ![Step 5](image/s4.png) 48 | 49 | ![Step 6](image/s5.png) 50 | 51 | ![Step 7](image/s6.png) 52 | 53 | 6. **Click "Done".** 54 | 55 | ![Step 8](image/s7.png) 56 | 57 | 7. **"All strings have been successfully translated" message shown.** 58 | 59 | ![Step 9](image/s8.png) 60 | 61 | 8. **The translated strings in XML format will be saved in the output folder within your specified folder Name.** 62 | 63 | ![Step 10](image/s9.png) 64 | 65 | 9. **Open Android Studio Project and paste all values folder in an Src Folder using Explorer.** 66 | 67 | ![Step 11](image/s10.png) 68 | 69 | 10. **All translated strings successfully imported.** 70 | 71 | ![Step 12](image/s11.png) 72 | ![Step 13](image/s12.png) 73 | ![Step 14](image/s13.png) 74 | 75 | 76 | ## Contributing 🤝 77 | 78 | Join us in shaping the future of this project – your contributions are invaluable! 79 | 80 | 1. **Fork the repository** and create a new branch for your feature or bug fix. 81 | 2. Select an existing issue or create a new one, and request that it be assigned. 82 | 3. If the issue is assigned, make your changes and ensure that the code follows the project's coding standards. 83 | 4. Write tests to cover your changes and ensure that existing tests pass. 84 | 5. Submit a **pull request**, explaining the changes and the problem it addresses. 85 | 6. A project maintainer will review your pull request. Please be patient during the review process. 86 | 7. Upon approval, your changes will be merged into the main branch. 87 | Thank you for your contribution! 🚀 88 | 89 | 90 | ## Support the Project 91 | 92 | If you find this tutorial series helpful and would like to support the development of more content, consider buying me a coffee! Your support helps in creating high-quality tutorials. 93 | 94 | [![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-Donate-orange?style=for-the-badge&logo=buy-me-a-coffee)](https://www.buymeacoffee.com/codingmeet) 95 | 96 | Your generosity is greatly appreciated! Thank you for supporting this project. 97 | 98 | ## Author 99 | 100 | **Meet** 101 | 102 | If you appreciate my work, consider following me on LinkedIn, YouTube, and adding this project to your favorites on GitHub. Stay tuned for more insights into app development, Kotlin, and more! 103 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.compose.desktop.application.dsl.TargetFormat 2 | 3 | plugins { 4 | kotlin("jvm") version "1.9.0" 5 | id("org.jetbrains.compose") version "1.5.0" 6 | } 7 | 8 | 9 | dependencies { 10 | // Note, if you develop a library, you should use compose.desktop.common. 11 | // compose.desktop.currentOs should be used in launcher-sourceSet 12 | // (in a separate module for demo project and in testMain). 13 | // With compose.desktop.common you will also lose @Preview functionality 14 | implementation(compose.desktop.currentOs) 15 | implementation(compose.runtime) 16 | implementation(compose.foundation) 17 | implementation(compose.material) 18 | // Add the org.json library for handling JSON data 19 | implementation("org.json:json:20210307") 20 | 21 | } 22 | java { 23 | toolchain { 24 | languageVersion.set(JavaLanguageVersion.of(17)) 25 | } 26 | } 27 | compose.desktop { 28 | application { 29 | mainClass = "MainKt" 30 | nativeDistributions { 31 | macOS { 32 | iconFile.set(project.file("translate.icns")) 33 | } 34 | windows { 35 | iconFile.set(project.file("translate.ico")) 36 | } 37 | linux { 38 | iconFile.set(project.file("translate.png")) 39 | } 40 | targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) 41 | packageName = "com.coding.meet.translate" 42 | description = "String Translator Desktop App" 43 | vendor = "Meet" 44 | version = "1.0.0" 45 | licenseFile.set(project.file("LICENSE")) 46 | outputBaseDir.set(project.rootDir.resolve("customOutputDir")) 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | kotlin.code.style=official 3 | zipStoreBase=GRADLE_USER_HOME 4 | #Gradle 5 | org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" 6 | 7 | 8 | 9 | #Development 10 | development=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/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-8.0-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /image/StringTranslatorDesktopApp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/StringTranslatorDesktopApp.png -------------------------------------------------------------------------------- /image/s0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s0.png -------------------------------------------------------------------------------- /image/s1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s1.png -------------------------------------------------------------------------------- /image/s10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s10.png -------------------------------------------------------------------------------- /image/s11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s11.png -------------------------------------------------------------------------------- /image/s12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s12.png -------------------------------------------------------------------------------- /image/s13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s13.png -------------------------------------------------------------------------------- /image/s2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s2.png -------------------------------------------------------------------------------- /image/s3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s3.png -------------------------------------------------------------------------------- /image/s4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s4.png -------------------------------------------------------------------------------- /image/s5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s5.png -------------------------------------------------------------------------------- /image/s6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s6.png -------------------------------------------------------------------------------- /image/s7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s7.png -------------------------------------------------------------------------------- /image/s8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s8.png -------------------------------------------------------------------------------- /image/s9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/image/s9.png -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file must *NOT* be checked into Version Control Systems, 2 | # as it contains information specific to your local configuration. 3 | # 4 | # Location of the SDK. This is only used by Gradle. 5 | # For customization when using a Version Control System, please read the 6 | # header note. 7 | #Thu Sep 28 11:57:50 IST 2023 8 | sdk.dir=D\:\\AndroidStudio\\Sdk 9 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") 2 | 3 | pluginManagement { 4 | repositories { 5 | maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") 6 | google() 7 | gradlePluginPortal() 8 | mavenCentral() 9 | } 10 | } 11 | 12 | dependencyResolutionManagement { 13 | repositories { 14 | google() 15 | mavenCentral() 16 | maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") 17 | } 18 | } 19 | 20 | rootProject.name = "StringTranslatorDesktopApp" -------------------------------------------------------------------------------- /src/main/kotlin/App.kt: -------------------------------------------------------------------------------- 1 | 2 | import androidx.compose.desktop.ui.tooling.preview.Preview 3 | import androidx.compose.foundation.layout.Arrangement 4 | import androidx.compose.foundation.layout.Column 5 | import androidx.compose.foundation.layout.Row 6 | import androidx.compose.foundation.layout.fillMaxHeight 7 | import androidx.compose.foundation.layout.fillMaxSize 8 | import androidx.compose.foundation.layout.fillMaxWidth 9 | import androidx.compose.foundation.layout.height 10 | import androidx.compose.foundation.layout.padding 11 | import androidx.compose.material.MaterialTheme 12 | import androidx.compose.runtime.Composable 13 | import androidx.compose.runtime.getValue 14 | import androidx.compose.runtime.mutableStateOf 15 | import androidx.compose.runtime.remember 16 | import androidx.compose.runtime.setValue 17 | import androidx.compose.ui.Alignment 18 | import androidx.compose.ui.Modifier 19 | import androidx.compose.ui.unit.dp 20 | import kotlinx.coroutines.CoroutineScope 21 | import kotlinx.coroutines.Dispatchers 22 | import kotlinx.coroutines.delay 23 | import kotlinx.coroutines.launch 24 | import screen.CustomButton 25 | import screen.CustomTextField 26 | import screen.SelectCountries 27 | import screen.Toast 28 | import screen.translateDialog 29 | import utils.WindowState 30 | import utils.isValidXml 31 | import utils.languageList 32 | import utils.openOutputFile 33 | 34 | @Composable 35 | @Preview 36 | fun App() { 37 | 38 | var isWindowShow by remember { mutableStateOf(WindowState.NO_STATE) } 39 | var stringState by remember { mutableStateOf("") } 40 | var folderState by remember { mutableStateOf("") } 41 | var countryListState by remember { mutableStateOf(languageList) } 42 | var isShowToast by remember { mutableStateOf(false) } 43 | var toastMessage by remember { mutableStateOf("") } 44 | MaterialTheme { 45 | if (isShowToast) { 46 | Toast(toastMessage) { 47 | isShowToast = false 48 | } 49 | } 50 | Column(Modifier.fillMaxSize().padding(8.dp)) { 51 | CustomTextField( 52 | stringState, 53 | "Enter the Strings", 54 | Modifier.fillMaxHeight().weight(0.9f, true), 55 | ) { stringState = it } 56 | 57 | Row( 58 | modifier = Modifier 59 | .fillMaxWidth() 60 | .weight(0.1f), 61 | horizontalArrangement = Arrangement.SpaceBetween, 62 | verticalAlignment = Alignment.CenterVertically 63 | ) { 64 | CustomButton( 65 | modifier = Modifier.weight(1f).height(50.dp), 66 | "Select Languages", 67 | onClick = { 68 | isWindowShow = WindowState.SELECT_COUNTRY 69 | }) 70 | CustomTextField( 71 | folderState, 72 | "Enter the Folder Name", 73 | Modifier 74 | .padding(start = 8.dp, end = 8.dp) 75 | .weight(1f) // Use weight to make the TextField fill the available space 76 | .height(50.dp) 77 | ) { folderState = it } 78 | CustomButton( 79 | modifier = Modifier.weight(1f).height(50.dp), 80 | "Translate", 81 | onClick = { 82 | if (stringState.isEmpty()) { 83 | isShowToast = true 84 | toastMessage = "Error: Please enter the source strings" 85 | CoroutineScope(Dispatchers.IO).launch { 86 | delay(3000) 87 | isShowToast = false 88 | } 89 | } else if (!isValidXml(stringState)) { 90 | isShowToast = true 91 | toastMessage = 92 | "Error: Please enter the source strings in XML format into the provided text field." 93 | CoroutineScope(Dispatchers.IO).launch { 94 | delay(3000) 95 | isShowToast = false 96 | } 97 | } else if (folderState.isEmpty()) { 98 | isShowToast = true 99 | toastMessage = 100 | "Error: Enter the folder name where you want to store the translated strings." 101 | CoroutineScope(Dispatchers.IO).launch { 102 | delay(3000) 103 | isShowToast = false 104 | } 105 | } else if (!countryListState.any { it.isChecked }) { 106 | isShowToast = true 107 | toastMessage = 108 | "Error: Please select at least one target language before translating." 109 | CoroutineScope(Dispatchers.IO).launch { 110 | delay(3000) 111 | isShowToast = false 112 | } 113 | } else { 114 | isWindowShow = WindowState.CONVERT_TRANSLATE 115 | } 116 | } 117 | ) 118 | } 119 | } 120 | when (isWindowShow) { 121 | WindowState.SELECT_COUNTRY -> { 122 | SelectCountries(countryListState) { 123 | countryListState = it 124 | isWindowShow = WindowState.NO_STATE 125 | if (!it.any { elements -> elements.isChecked }) { 126 | isShowToast = true 127 | toastMessage = 128 | "Error: Please select at least one target language before translating." 129 | CoroutineScope(Dispatchers.IO).launch { 130 | delay(3000) 131 | isShowToast = false 132 | } 133 | } 134 | } 135 | } 136 | 137 | WindowState.CONVERT_TRANSLATE -> { 138 | translateDialog( 139 | countryListState.filter { it.isChecked }, 140 | folderState, 141 | stringState, 142 | { errorMsg -> 143 | isShowToast = true 144 | toastMessage = "Error: $errorMsg" 145 | CoroutineScope(Dispatchers.IO).launch { 146 | delay(3000) 147 | isShowToast = false 148 | } 149 | }, 150 | { successMsg -> 151 | isWindowShow = WindowState.NO_STATE 152 | if (successMsg.trim().isNotEmpty()) { 153 | stringState = "" 154 | folderState = "" 155 | countryListState = languageList 156 | isShowToast = true 157 | toastMessage = successMsg 158 | CoroutineScope(Dispatchers.IO).launch { 159 | delay(3000) 160 | isShowToast = false 161 | } 162 | openOutputFile() 163 | } 164 | }) 165 | } 166 | 167 | else -> { 168 | 169 | } 170 | } 171 | } 172 | } -------------------------------------------------------------------------------- /src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import androidx.compose.foundation.border 2 | import androidx.compose.foundation.clickable 3 | import androidx.compose.foundation.layout.Box 4 | import androidx.compose.foundation.layout.Column 5 | import androidx.compose.foundation.layout.fillMaxSize 6 | import androidx.compose.foundation.layout.fillMaxWidth 7 | import androidx.compose.foundation.layout.height 8 | import androidx.compose.foundation.layout.padding 9 | import androidx.compose.foundation.shape.RoundedCornerShape 10 | import androidx.compose.foundation.window.WindowDraggableArea 11 | import androidx.compose.material.Icon 12 | import androidx.compose.material.Text 13 | import androidx.compose.material.TopAppBar 14 | import androidx.compose.material.icons.Icons 15 | import androidx.compose.material.icons.rounded.Close 16 | import androidx.compose.material.icons.rounded.KeyboardArrowDown 17 | import androidx.compose.runtime.Composable 18 | import androidx.compose.ui.Alignment 19 | import androidx.compose.ui.Modifier 20 | import androidx.compose.ui.draw.clip 21 | import androidx.compose.ui.graphics.Color 22 | import androidx.compose.ui.res.painterResource 23 | import androidx.compose.ui.text.font.FontWeight 24 | import androidx.compose.ui.text.style.TextAlign 25 | import androidx.compose.ui.unit.dp 26 | import androidx.compose.ui.window.Window 27 | import androidx.compose.ui.window.WindowPosition 28 | import androidx.compose.ui.window.WindowScope 29 | import androidx.compose.ui.window.WindowState 30 | import androidx.compose.ui.window.application 31 | import theme.TextFieldBackground 32 | 33 | fun main() = application { 34 | val windowState = WindowState( 35 | width = 1280.dp, 36 | height = 720.dp, 37 | position = WindowPosition(Alignment.Center) 38 | ) 39 | Window( 40 | onCloseRequest = ::exitApplication, 41 | title = "String Translator Desktop App", 42 | state = windowState, 43 | resizable = false, 44 | undecorated = true, 45 | icon = painterResource("translate.svg") 46 | ) { 47 | Column( 48 | Modifier.fillMaxSize() 49 | .border(width = 2.dp, color = TextFieldBackground, shape = RoundedCornerShape(2.dp)) 50 | .clip(RoundedCornerShape(bottomStart = 120.dp, bottomEnd = 120.dp)) 51 | ) { 52 | AppWindowTitleBar(isMinimized = { 53 | windowState.isMinimized = true 54 | }) { exitApplication() } 55 | App() 56 | } 57 | } 58 | } 59 | 60 | @Composable 61 | fun WindowScope.AppWindowTitleBar( 62 | isWindow: Boolean = true, 63 | isMinimized: () -> Unit = { }, 64 | onClose: () -> Unit, 65 | ) = 66 | WindowDraggableArea { 67 | Box( 68 | Modifier.fillMaxWidth() 69 | .height(48.dp) 70 | .padding(horizontal = 16.dp), 71 | contentAlignment = Alignment.CenterEnd 72 | ) { 73 | TopAppBar( 74 | title = { 75 | Text( 76 | "String Translator Desktop App", 77 | textAlign = TextAlign.Center, 78 | fontWeight = FontWeight.Bold, 79 | modifier = Modifier.fillMaxWidth() 80 | ) 81 | }, 82 | contentColor = Color.White, 83 | backgroundColor = TextFieldBackground, 84 | modifier = Modifier.fillMaxSize().padding(horizontal = 160.dp) 85 | .clip(RoundedCornerShape(bottomStart = 100.dp, bottomEnd = 100.dp)) 86 | ) 87 | if (isWindow) { 88 | Icon( 89 | imageVector = Icons.Rounded.KeyboardArrowDown, 90 | contentDescription = "Minimise", 91 | tint = TextFieldBackground, 92 | modifier = Modifier.padding(end = 32.dp).clickable { isMinimized() } 93 | ) 94 | } 95 | 96 | Icon( 97 | imageVector = Icons.Rounded.Close, 98 | contentDescription = "Close", 99 | tint = TextFieldBackground, 100 | modifier = Modifier.padding(start = 8.dp).clickable { onClose() } 101 | ) 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/kotlin/models/Language.kt: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | data class Language( 4 | val code: String, 5 | val name: String, 6 | var isChecked: Boolean = false 7 | ) -------------------------------------------------------------------------------- /src/main/kotlin/models/StringModel.kt: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | data class StringModel( 4 | val name: String, 5 | val isTranslatable: Boolean = true, 6 | val textContent: String 7 | ) -------------------------------------------------------------------------------- /src/main/kotlin/screen/Components.kt: -------------------------------------------------------------------------------- 1 | package screen 2 | 3 | import androidx.compose.foundation.background 4 | import androidx.compose.foundation.layout.Box 5 | import androidx.compose.foundation.layout.fillMaxWidth 6 | import androidx.compose.foundation.layout.height 7 | import androidx.compose.foundation.layout.padding 8 | import androidx.compose.foundation.layout.wrapContentHeight 9 | import androidx.compose.foundation.shape.RoundedCornerShape 10 | import androidx.compose.material.Button 11 | import androidx.compose.material.ButtonDefaults 12 | import androidx.compose.material.Icon 13 | import androidx.compose.material.IconButton 14 | import androidx.compose.material.MaterialTheme 15 | import androidx.compose.material.Text 16 | import androidx.compose.material.TextField 17 | import androidx.compose.material.TextFieldDefaults 18 | import androidx.compose.material.icons.Icons 19 | import androidx.compose.material.icons.filled.Close 20 | import androidx.compose.runtime.Composable 21 | import androidx.compose.ui.Alignment 22 | import androidx.compose.ui.Modifier 23 | import androidx.compose.ui.draw.clip 24 | import androidx.compose.ui.graphics.Color 25 | import androidx.compose.ui.text.font.FontWeight 26 | import androidx.compose.ui.unit.dp 27 | import androidx.compose.ui.unit.sp 28 | import theme.PurpleBlue 29 | import theme.TextFieldBackground 30 | 31 | @Composable 32 | fun CustomTextField( 33 | text: String, 34 | placeHolderText: String, 35 | modifier: Modifier, 36 | readOnly: Boolean = false, 37 | focusable: Boolean = true, 38 | onValueChange: (String) -> Unit, 39 | ) { 40 | TextField( 41 | value = text, 42 | onValueChange = onValueChange, 43 | label = { Text(placeHolderText, color = Color.White) }, 44 | colors = TextFieldDefaults.textFieldColors( 45 | textColor = Color.White, 46 | placeholderColor = Color.White.copy(alpha = 0.4f), 47 | focusedIndicatorColor = if (focusable) PurpleBlue else Color.White, 48 | backgroundColor = TextFieldBackground 49 | ), 50 | readOnly = readOnly, 51 | modifier = modifier.fillMaxWidth().clip(RoundedCornerShape(12.dp)).height(280.dp) 52 | ) 53 | } 54 | 55 | @Composable 56 | fun CustomButton(modifier: Modifier, text: String, onClick: () -> Unit, isEnable: Boolean = true) { 57 | Button( 58 | onClick = onClick, 59 | colors = ButtonDefaults.buttonColors(TextFieldBackground, Color.White), 60 | shape = RoundedCornerShape(12.dp), 61 | enabled = isEnable, 62 | modifier = modifier.fillMaxWidth() 63 | ) { 64 | Text(text, fontWeight = FontWeight.Bold, fontSize = 16.sp) 65 | } 66 | } 67 | 68 | @Composable 69 | fun Toast(message: String, onDismiss: () -> Unit) { 70 | val modifier = 71 | Modifier.padding(start = 8.dp, end = 8.dp, top = 8.dp).clip(RoundedCornerShape(12.dp)) 72 | .background( 73 | if (message.startsWith("Error")) { 74 | MaterialTheme.colors.error 75 | } else { 76 | Color(0xFF4BB543) 77 | } 78 | ).fillMaxWidth() 79 | .wrapContentHeight().height(40.dp) 80 | 81 | Box( 82 | modifier = modifier, contentAlignment = Alignment.Center 83 | ) { 84 | Text( 85 | text = message, color = Color.White, fontSize = 18.sp, fontWeight = FontWeight.Bold 86 | ) 87 | 88 | IconButton( 89 | onClick = onDismiss, modifier = Modifier.align(Alignment.CenterEnd) 90 | ) { 91 | Icon( 92 | imageVector = Icons.Default.Close, contentDescription = "Close", tint = Color.White 93 | ) 94 | } 95 | } 96 | } 97 | 98 | -------------------------------------------------------------------------------- /src/main/kotlin/screen/SelectCountryScreen.kt: -------------------------------------------------------------------------------- 1 | package screen 2 | 3 | import AppWindowTitleBar 4 | import androidx.compose.foundation.border 5 | import androidx.compose.foundation.clickable 6 | import androidx.compose.foundation.layout.Arrangement 7 | import androidx.compose.foundation.layout.Column 8 | import androidx.compose.foundation.layout.Row 9 | import androidx.compose.foundation.layout.fillMaxSize 10 | import androidx.compose.foundation.layout.fillMaxWidth 11 | import androidx.compose.foundation.layout.padding 12 | import androidx.compose.foundation.layout.wrapContentHeight 13 | import androidx.compose.foundation.lazy.grid.GridCells 14 | import androidx.compose.foundation.lazy.grid.LazyVerticalGrid 15 | import androidx.compose.foundation.lazy.grid.itemsIndexed 16 | import androidx.compose.foundation.shape.RoundedCornerShape 17 | import androidx.compose.material.Checkbox 18 | import androidx.compose.material.CheckboxDefaults 19 | import androidx.compose.material.Text 20 | import androidx.compose.runtime.Composable 21 | import androidx.compose.runtime.getValue 22 | import androidx.compose.runtime.mutableStateOf 23 | import androidx.compose.runtime.remember 24 | import androidx.compose.runtime.setValue 25 | import androidx.compose.ui.Alignment 26 | import androidx.compose.ui.Modifier 27 | import androidx.compose.ui.res.painterResource 28 | import androidx.compose.ui.text.font.FontWeight 29 | import androidx.compose.ui.unit.dp 30 | import androidx.compose.ui.unit.sp 31 | import androidx.compose.ui.window.DialogState 32 | import androidx.compose.ui.window.DialogWindow 33 | import androidx.compose.ui.window.WindowPosition 34 | import models.Language 35 | import theme.TextFieldBackground 36 | 37 | @Composable 38 | fun SelectCountries( 39 | languageList: MutableList, 40 | onDismiss: (MutableList) -> Unit, 41 | ) { 42 | var countryListState by remember { mutableStateOf(languageList) } 43 | val dialogState = DialogState( 44 | width = 1000.dp, height = 720.dp, position = WindowPosition(Alignment.Center) 45 | ) 46 | var selectAllState by remember { mutableStateOf(languageList.all { it.isChecked }) } 47 | 48 | DialogWindow( 49 | state = dialogState, 50 | onCloseRequest = { onDismiss(countryListState) }, 51 | title = "Select Language", 52 | undecorated = true, 53 | resizable = false, 54 | icon = painterResource("translate.svg"), 55 | content = { 56 | Column( 57 | Modifier.fillMaxSize() 58 | .border( 59 | width = 2.dp, 60 | color = TextFieldBackground, 61 | shape = RoundedCornerShape(2.dp) 62 | ) 63 | ) { 64 | AppWindowTitleBar(isWindow = false) { onDismiss(countryListState) } 65 | Column( 66 | horizontalAlignment = Alignment.CenterHorizontally, 67 | verticalArrangement = Arrangement.Top 68 | 69 | ) { 70 | Row( 71 | horizontalArrangement = Arrangement.SpaceEvenly, 72 | verticalAlignment = Alignment.CenterVertically, 73 | modifier = Modifier.clickable { 74 | selectAllState = !selectAllState 75 | countryListState = 76 | countryListState.map { it.copy(isChecked = selectAllState) } 77 | .toMutableList() 78 | 79 | }) { 80 | Checkbox( 81 | checked = selectAllState, 82 | onCheckedChange = { 83 | selectAllState = it 84 | countryListState = 85 | countryListState.map { element -> element.copy(isChecked = selectAllState) } 86 | .toMutableList() 87 | 88 | }, 89 | colors = CheckboxDefaults.colors(checkedColor = TextFieldBackground) 90 | ) 91 | Text( 92 | text = "Select All", 93 | fontSize = 18.sp, 94 | fontWeight = FontWeight.SemiBold, 95 | modifier = Modifier.padding(end = 8.dp) 96 | ) 97 | } 98 | 99 | LazyVerticalGrid( 100 | columns = GridCells.Fixed(5), 101 | verticalArrangement = Arrangement.Center, 102 | horizontalArrangement = Arrangement.Center, 103 | modifier = Modifier.fillMaxSize() 104 | ) { 105 | itemsIndexed(countryListState) { index, language -> 106 | Row(horizontalArrangement = Arrangement.Center, 107 | verticalAlignment = Alignment.CenterVertically, 108 | modifier = Modifier.fillMaxWidth().clickable { 109 | countryListState = countryListState.toMutableList().apply { 110 | this[index] = language.copy(isChecked = !language.isChecked) 111 | } 112 | selectAllState = languageList.all { it.isChecked } 113 | }) { 114 | Checkbox( 115 | checked = language.isChecked, 116 | onCheckedChange = { 117 | countryListState = countryListState.toMutableList().apply { 118 | this[index] = language.copy(isChecked = it) 119 | } 120 | selectAllState = languageList.all { it.isChecked } 121 | }, 122 | colors = CheckboxDefaults.colors(checkedColor = TextFieldBackground) 123 | ) 124 | Text( 125 | text = "${language.name} (${language.code})", 126 | fontSize = 18.sp, 127 | fontWeight = FontWeight.SemiBold, 128 | modifier = Modifier.fillMaxWidth().wrapContentHeight() 129 | ) 130 | } 131 | } 132 | } 133 | } 134 | } 135 | }) 136 | } 137 | -------------------------------------------------------------------------------- /src/main/kotlin/screen/TranslateScreen.kt: -------------------------------------------------------------------------------- 1 | package screen 2 | 3 | import AppWindowTitleBar 4 | import androidx.compose.foundation.border 5 | import androidx.compose.foundation.layout.Arrangement 6 | import androidx.compose.foundation.layout.Column 7 | import androidx.compose.foundation.layout.Row 8 | import androidx.compose.foundation.layout.Spacer 9 | import androidx.compose.foundation.layout.fillMaxSize 10 | import androidx.compose.foundation.layout.fillMaxWidth 11 | import androidx.compose.foundation.layout.height 12 | import androidx.compose.foundation.layout.padding 13 | import androidx.compose.foundation.layout.wrapContentHeight 14 | import androidx.compose.foundation.lazy.grid.GridCells 15 | import androidx.compose.foundation.lazy.grid.LazyVerticalGrid 16 | import androidx.compose.foundation.lazy.grid.itemsIndexed 17 | import androidx.compose.foundation.shape.RoundedCornerShape 18 | import androidx.compose.material.Checkbox 19 | import androidx.compose.material.CheckboxDefaults 20 | import androidx.compose.material.LinearProgressIndicator 21 | import androidx.compose.material.Text 22 | import androidx.compose.runtime.Composable 23 | import androidx.compose.runtime.getValue 24 | import androidx.compose.runtime.mutableStateOf 25 | import androidx.compose.runtime.remember 26 | import androidx.compose.runtime.setValue 27 | import androidx.compose.ui.Alignment 28 | import androidx.compose.ui.Modifier 29 | import androidx.compose.ui.graphics.StrokeCap 30 | import androidx.compose.ui.res.painterResource 31 | import androidx.compose.ui.text.font.FontWeight 32 | import androidx.compose.ui.unit.dp 33 | import androidx.compose.ui.unit.sp 34 | import androidx.compose.ui.window.DialogState 35 | import androidx.compose.ui.window.DialogWindow 36 | import androidx.compose.ui.window.WindowPosition 37 | import kotlinx.coroutines.CoroutineScope 38 | import kotlinx.coroutines.Dispatchers 39 | import kotlinx.coroutines.delay 40 | import kotlinx.coroutines.launch 41 | import models.Language 42 | import theme.TextFieldBackground 43 | import translate.translateHttpURLConnection 44 | import utils.createOutputMainFolder 45 | import utils.createStringFolder 46 | import utils.defaultLanguageCode 47 | import utils.endResourcesWrite 48 | import utils.readAllStrings 49 | import utils.startResourcesWrite 50 | import utils.stringWrite 51 | import java.net.URLEncoder 52 | 53 | 54 | @Composable 55 | fun translateDialog( 56 | languageList: List, 57 | folderName: String, 58 | stringState: String, 59 | errorCallback: (String) -> Unit, 60 | onDismiss: (String) -> Unit, 61 | ) { 62 | var checkedCountryListState by remember { mutableStateOf(languageList) } 63 | var progressState by remember { mutableStateOf(0) } 64 | val dialogState = DialogState( 65 | width = 1000.dp, height = 720.dp, position = WindowPosition(Alignment.Center) 66 | ) 67 | DialogWindow( 68 | state = dialogState, 69 | onCloseRequest = { 70 | if (progressState == 100) { 71 | onDismiss("All strings have been successfully translated.") 72 | } else { 73 | onDismiss("Translation canceled by you.") 74 | } 75 | }, 76 | title = "Translating All String", 77 | undecorated = true, 78 | resizable = false, 79 | icon = painterResource("translate.svg"), 80 | content = { 81 | Column( 82 | Modifier.fillMaxSize() 83 | .border( 84 | width = 2.dp, 85 | color = TextFieldBackground, 86 | shape = RoundedCornerShape(2.dp) 87 | ) 88 | ) { 89 | AppWindowTitleBar(isWindow = false) { 90 | if (progressState == 100) { 91 | onDismiss("All strings have been successfully translated.") 92 | } else { 93 | onDismiss("Translation canceled by you.") 94 | } 95 | } 96 | 97 | Column( 98 | modifier = Modifier 99 | .padding(16.dp), 100 | verticalArrangement = Arrangement.Center 101 | ) { 102 | LinearProgressIndicator( 103 | progressState.toFloat() / 100, 104 | modifier = Modifier 105 | .height(10.dp) 106 | .fillMaxWidth(), 107 | color = TextFieldBackground, 108 | strokeCap = StrokeCap.Round 109 | ) 110 | Spacer(modifier = Modifier.height(10.dp)) 111 | Row( 112 | modifier = Modifier 113 | .fillMaxWidth(), 114 | horizontalArrangement = Arrangement.SpaceAround, 115 | ) { 116 | Text( 117 | "Progress: ${progressState}%", 118 | fontSize = 18.sp, 119 | fontWeight = FontWeight.SemiBold 120 | ) 121 | } 122 | if (progressState == 100) { 123 | Spacer(modifier = Modifier.height(10.dp)) 124 | Row( 125 | modifier = Modifier 126 | .fillMaxWidth(), 127 | horizontalArrangement = Arrangement.SpaceAround, 128 | ) { 129 | CustomButton(Modifier, "Done", onClick = { 130 | onDismiss("All strings have been successfully translated.") 131 | }) 132 | } 133 | } 134 | Spacer(modifier = Modifier.height(10.dp)) 135 | LazyVerticalGrid( 136 | columns = GridCells.Fixed(5), 137 | verticalArrangement = Arrangement.Top, 138 | horizontalArrangement = Arrangement.Center, 139 | modifier = Modifier 140 | ) { 141 | itemsIndexed(checkedCountryListState) { _, language -> 142 | Row( 143 | horizontalArrangement = Arrangement.SpaceEvenly, 144 | verticalAlignment = Alignment.CenterVertically, 145 | modifier = Modifier.fillMaxWidth() 146 | ) { 147 | Checkbox( 148 | checked = !language.isChecked, 149 | enabled = false, 150 | onCheckedChange = {}, 151 | colors = CheckboxDefaults.colors( 152 | checkedColor = TextFieldBackground, 153 | disabledColor = TextFieldBackground, 154 | disabledIndeterminateColor = TextFieldBackground 155 | ) 156 | ) 157 | Text( 158 | text = "${language.name} (${language.code})", 159 | fontSize = 18.sp, 160 | fontWeight = FontWeight.SemiBold, 161 | modifier = Modifier.fillMaxWidth().wrapContentHeight() 162 | ) 163 | } 164 | } 165 | } 166 | } 167 | } 168 | }) 169 | CoroutineScope(Dispatchers.IO).launch { 170 | try { 171 | createOutputMainFolder(folderName) 172 | val allStrings = readAllStrings(stringState) 173 | progressState = 0 174 | delay(300) 175 | languageList 176 | .forEachIndexed { index, language -> 177 | val stringFile = 178 | createStringFolder(folderName, language.code) 179 | stringFile.startResourcesWrite() 180 | allStrings.forEachIndexed { _, stringModel -> 181 | 182 | val (name, isTranslatable, textContent) = stringModel 183 | if (isTranslatable) { 184 | translateHttpURLConnection( 185 | URLEncoder.encode(textContent, "UTF-8"), 186 | URLEncoder.encode(defaultLanguageCode, "UTF-8"), 187 | URLEncoder.encode(language.code, "UTF-8"), 188 | { convertedString -> 189 | stringFile.stringWrite(name, convertedString) 190 | }, { errorMsg -> 191 | errorCallback(errorMsg) 192 | }) 193 | delay(300) 194 | } else { 195 | stringFile.stringWrite(name, textContent, false) 196 | } 197 | progressState = 198 | ((index.toFloat() / (languageList.size)) * 100).toInt() 199 | } 200 | stringFile.endResourcesWrite() 201 | checkedCountryListState = 202 | checkedCountryListState.toMutableList().apply { 203 | this[index] = language.copy(isChecked = false) 204 | } 205 | delay(500) 206 | } 207 | progressState = 100 208 | } catch (e: Exception) { 209 | e.printStackTrace() 210 | } 211 | } 212 | } -------------------------------------------------------------------------------- /src/main/kotlin/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | val PurpleBlue = Color(0xFF7F52FF) 6 | val TextFieldBackground = Color(0xFF000000) -------------------------------------------------------------------------------- /src/main/kotlin/translate/TranslationConnection.kt: -------------------------------------------------------------------------------- 1 | package translate 2 | 3 | 4 | import org.json.JSONArray 5 | import org.json.JSONObject 6 | import java.net.HttpURLConnection 7 | import java.net.URL 8 | 9 | private fun getTextHttpURLConnection(url: String, onErrorCallback: (String) -> Unit): String { 10 | var response = "" 11 | try { 12 | val connection = URL(url).openConnection() as HttpURLConnection 13 | val inputStream = connection.inputStream 14 | response = inputStream.bufferedReader().use { it.readText() } 15 | } catch (e: Exception) { 16 | e.printStackTrace() 17 | onErrorCallback(e.message.toString()) 18 | } 19 | return response 20 | } 21 | 22 | fun translateHttpURLConnection( 23 | query: String, 24 | sourceLang: String, 25 | targetLang: String, 26 | onSuccessCallback: (String) -> Unit, 27 | onErrorCallback: (String) -> Unit, 28 | isFirstTime: Boolean = true, 29 | ) { 30 | try { 31 | val convertedStringB = StringBuilder() 32 | var responseText = 33 | getTextHttpURLConnection( 34 | String.format( 35 | "https://translate.google.com/translate_a/single?&client=gtx&sl=%s&tl=%s&q=%s&dt=t", 36 | sourceLang, 37 | targetLang, 38 | query 39 | ), 40 | onErrorCallback 41 | ) 42 | if (responseText.isEmpty()) { 43 | responseText = 44 | getTextHttpURLConnection( 45 | String.format( 46 | "https://clients4.google.com/translate_a/t?client=dict-chrome-ex&sl=%s&tl=%s&q=%s&dt=t", 47 | sourceLang, 48 | targetLang, 49 | query 50 | ), 51 | onErrorCallback 52 | ) 53 | if (responseText.isEmpty()) { 54 | responseText = 55 | getTextHttpURLConnection( 56 | String.format( 57 | "https://translate.google.com/m?sl=%s&tl=%s&q=%s", 58 | sourceLang, 59 | targetLang, 60 | query 61 | ), 62 | onErrorCallback 63 | ) 64 | if (responseText.isEmpty()) { 65 | if (isFirstTime) { 66 | convertedStringB.append( 67 | translateHttpURLConnection( 68 | sourceLang, 69 | targetLang, 70 | query, 71 | onSuccessCallback, 72 | onErrorCallback, 73 | false, 74 | ) 75 | ) 76 | } else { 77 | println("Error" + "Url Failed") 78 | } 79 | } else { 80 | convertedStringB.append(getTranslationData(responseText, onErrorCallback)) 81 | } 82 | } else { 83 | convertedStringB.append(getJsonObjectResponseToString(responseText)) 84 | } 85 | } else { 86 | convertedStringB.append(getJsonArrayResponseToString(responseText)) 87 | } 88 | return onSuccessCallback(convertedStringB.toString()) 89 | } catch (e: Exception) { 90 | e.printStackTrace() 91 | onErrorCallback(e.message.toString()) 92 | } 93 | return onSuccessCallback("") 94 | } 95 | 96 | private fun getJsonObjectResponseToString(responseText: String): String { 97 | val sb = StringBuilder() 98 | val jsonObject = JSONObject(responseText) 99 | if (jsonObject.has("sentences")) { 100 | val jsonArray = jsonObject.getJSONArray("sentences") 101 | for (i in 0 until jsonArray.length()) { 102 | val jsonObject1 = jsonArray.getJSONObject(i) 103 | if (jsonObject1.has("trans")) { 104 | sb.append(jsonObject1.getString("trans")) 105 | } 106 | } 107 | } 108 | return sb.toString() 109 | } 110 | 111 | private fun getJsonArrayResponseToString(responseText: String): String { 112 | val sb = StringBuilder() 113 | val jSONArray = JSONArray(responseText).getJSONArray(0) 114 | for (i in 0 until jSONArray.length()) { 115 | val string = jSONArray.getJSONArray(i).getString(0) 116 | if (string.isNotEmpty() && string != "null") { 117 | sb.append(string) 118 | } 119 | } 120 | return sb.toString() 121 | } 122 | 123 | fun getTranslationData(responseText: String, onErrorCallback: (String) -> Unit): String { 124 | try { 125 | var nativeText = "class=\"t0\">" 126 | val result = 127 | responseText.substring(responseText.indexOf(nativeText) + nativeText.length) 128 | .split("<".toRegex()).toTypedArray()[0] 129 | return if (result == "html>") { 130 | nativeText = "class=\"result-container\">" 131 | responseText.substring(responseText.indexOf(nativeText) + nativeText.length) 132 | .split("<".toRegex()).toTypedArray()[0] + "+" + "" 133 | } else { 134 | result 135 | } 136 | } catch (e: Exception) { 137 | e.printStackTrace() 138 | onErrorCallback(e.message.toString()) 139 | } 140 | return "" 141 | } 142 | -------------------------------------------------------------------------------- /src/main/kotlin/utils/Contant.kt: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import models.Language 4 | 5 | const val defaultLanguageCode = "en" 6 | 7 | enum class WindowState { 8 | NO_STATE, 9 | SELECT_COUNTRY, 10 | CONVERT_TRANSLATE 11 | } 12 | 13 | val languageList = mutableListOf( 14 | Language("af", "Afrikaans"), 15 | Language("agq", "Aghem"), 16 | Language("ak", "Akan"), 17 | Language("sq", "Albanian"), 18 | Language("am", "Amharic"), 19 | Language("ar", "Arabic"), 20 | Language("hy", "Armenian"), 21 | Language("as", "Assamese"), 22 | Language("ast", "Asturian"), 23 | Language("asa", "Asu"), 24 | Language("az", "Azerbaijani"), 25 | Language("ksf", "Bafia"), 26 | Language("bm", "Bambara"), 27 | Language("bn", "Bangla"), 28 | Language("bas", "Basaa"), 29 | Language("eu", "Basque"), 30 | Language("be", "Belarusian"), 31 | Language("bem", "Bemba"), 32 | Language("bez", "Bena"), 33 | Language("brx", "Bodo"), 34 | Language("bs", "Bosnian"), 35 | Language("br", "Breton"), 36 | Language("bg", "Bulgarian"), 37 | Language("my", "Burmese"), 38 | Language("yue", "Cantonese"), 39 | Language("ca", "Catalan"), 40 | Language("ceb", "Cebuano"), 41 | Language("tzm", "Central Atlas Tamazight"), 42 | Language("ckb", "Central Kurdish"), 43 | Language("ccp", "Chakma"), 44 | Language("ce", "Chechen"), 45 | Language("chr", "Cherokee"), 46 | Language("cgg", "Chiga"), 47 | Language("zh", "Chinese"), 48 | Language("ksh", "Colognian"), 49 | Language("kw", "Cornish"), 50 | Language("hr", "Croatian"), 51 | Language("cs", "Czech"), 52 | Language("da", "Danish"), 53 | Language("doi", "Dogri"), 54 | Language("dua", "Duala"), 55 | Language("nl", "Dutch"), 56 | Language("dz", "Dzongkha"), 57 | Language("ebu", "Embu"), 58 | Language("en", "English"), 59 | Language("eo", "Esperanto"), 60 | Language("et", "Estonian"), 61 | Language("ee", "Ewe"), 62 | Language("ewo", "Ewondo"), 63 | Language("fo", "Faroese"), 64 | Language("fil", "Filipino"), 65 | Language("fi", "Finnish"), 66 | Language("fr", "French"), 67 | Language("fur", "Friulian"), 68 | Language("ff", "Fulah"), 69 | Language("gl", "Galician"), 70 | Language("lg", "Ganda"), 71 | Language("ka", "Georgian"), 72 | Language("de", "German"), 73 | Language("el", "Greek"), 74 | Language("gu", "Gujarati"), 75 | Language("guz", "Gusii"), 76 | Language("ha", "Hausa"), 77 | Language("haw", "Hawaiian"), 78 | Language("he", "Hebrew"), 79 | Language("hi", "Hindi"), 80 | Language("hu", "Hungarian"), 81 | Language("is", "Icelandic"), 82 | Language("ig", "Igbo"), 83 | Language("smn", "Inari Sami"), 84 | Language("id", "Indonesian"), 85 | Language("ia", "Interlingua"), 86 | Language("ga", "Irish"), 87 | Language("it", "Italian"), 88 | Language("ja", "Japanese"), 89 | Language("jv", "Javanese"), 90 | Language("dyo", "Jola-Fonyi"), 91 | Language("kea", "Kabuverdianu"), 92 | Language("kab", "Kabyle"), 93 | Language("kkj", "Kako"), 94 | Language("kl", "Kalaallisut"), 95 | Language("kln", "Kalenjin"), 96 | Language("kam", "Kamba"), 97 | Language("kn", "Kannada"), 98 | Language("ks", "Kashmiri"), 99 | Language("kk", "Kazakh"), 100 | Language("km", "Khmer"), 101 | Language("ki", "Kikuyu"), 102 | Language("rw", "Kinyarwanda"), 103 | Language("kok", "Konkani"), 104 | Language("ko", "Korean"), 105 | Language("khq", "Koyra Chiini"), 106 | Language("ses", "Koyraboro Senni"), 107 | Language("ku", "Kurdish"), 108 | Language("nmg", "Kwasio"), 109 | Language("ky", "Kyrgyz"), 110 | Language("lkt", "Lakota"), 111 | Language("lag", "Langi"), 112 | Language("lo", "Lao"), 113 | Language("lv", "Latvian"), 114 | Language("ln", "Lingala"), 115 | Language("lt", "Lithuanian"), 116 | Language("nds", "Low German"), 117 | Language("dsb", "Lower Sorbian"), 118 | Language("lu", "Luba-Katanga"), 119 | Language("luo", "Luo"), 120 | Language("lb", "Luxembourgish"), 121 | Language("luy", "Luyia"), 122 | Language("mk", "Macedonian"), 123 | Language("jmc", "Machame"), 124 | Language("mai", "Maithili"), 125 | Language("mgh", "Makhuwa-Meetto"), 126 | Language("kde", "Makonde"), 127 | Language("mg", "Malagasy"), 128 | Language("ms", "Malay"), 129 | Language("ml", "Malayalam"), 130 | Language("mt", "Maltese"), 131 | Language("mni", "Manipuri"), 132 | Language("gv", "Manx"), 133 | Language("mi", "Maori"), 134 | Language("mr", "Marathi"), 135 | Language("mas", "Masai"), 136 | Language("mzn", "Mazanderani"), 137 | Language("mer", "Meru"), 138 | Language("mgo", "Metaʼ"), 139 | Language("mn", "Mongolian"), 140 | Language("mfe", "Morisyen"), 141 | Language("mua", "Mundang"), 142 | Language("naq", "Nama"), 143 | Language("ne", "Nepali"), 144 | Language("nnh", "Ngiemboon"), 145 | Language("jgo", "Ngomba"), 146 | Language("pcm", "Nigerian Pidgin"), 147 | Language("nd", "North Ndebele"), 148 | Language("lrc", "Northern Luri"), 149 | Language("se", "Northern Sami"), 150 | Language("no", "Norwegian"), 151 | Language("nb", "Norwegian Bokmål"), 152 | Language("nn", "Norwegian Nynorsk"), 153 | Language("nus", "Nuer"), 154 | Language("nyn", "Nyankole"), 155 | Language("or", "Odia"), 156 | Language("om", "Oromo"), 157 | Language("os", "Ossetic"), 158 | Language("ps", "Pashto"), 159 | Language("fa", "Persian"), 160 | Language("pl", "Polish"), 161 | Language("pt", "Portuguese"), 162 | Language("pa", "Punjabi"), 163 | Language("qu", "Quechua"), 164 | Language("ro", "Romanian"), 165 | Language("rm", "Romansh"), 166 | Language("rof", "Rombo"), 167 | Language("rn", "Rundi"), 168 | Language("ru", "Russian"), 169 | Language("rwk", "Rwa"), 170 | Language("sah", "Sakha"), 171 | Language("saq", "Samburu"), 172 | Language("sg", "Sango"), 173 | Language("sbp", "Sangu"), 174 | Language("sa", "Sanskrit"), 175 | Language("sat", "Santali"), 176 | Language("gd", "Scottish Gaelic"), 177 | Language("seh", "Sena"), 178 | Language("sr", "Serbian"), 179 | Language("ksb", "Shambala"), 180 | Language("sn", "Shona"), 181 | Language("ii", "Sichuan Yi"), 182 | Language("sd", "Sindhi"), 183 | Language("si", "Sinhala"), 184 | Language("sk", "Slovak"), 185 | Language("sl", "Slovenian"), 186 | Language("xog", "Soga"), 187 | Language("so", "Somali"), 188 | Language("es", "Spanish"), 189 | Language("zgh", "Standard Moroccan Tamazight"), 190 | Language("su", "Sundanese"), 191 | Language("sw", "Swahili"), 192 | Language("sv", "Swedish"), 193 | Language("gsw", "Swiss German"), 194 | Language("shi", "Tachelhit"), 195 | Language("dav", "Taita"), 196 | Language("tg", "Tajik"), 197 | Language("ta", "Tamil"), 198 | Language("twq", "Tasawaq"), 199 | Language("tt", "Tatar"), 200 | Language("te", "Telugu"), 201 | Language("teo", "Teso"), 202 | Language("th", "Thai"), 203 | Language("bo", "Tibetan"), 204 | Language("ti", "Tigrinya"), 205 | Language("to", "Tongan"), 206 | Language("tr", "Turkish"), 207 | Language("tk", "Turkmen"), 208 | Language("uk", "Ukrainian"), 209 | Language("hsb", "Upper Sorbian"), 210 | Language("ur", "Urdu"), 211 | Language("ug", "Uyghur"), 212 | Language("uz", "Uzbek"), 213 | Language("vai", "Vai"), 214 | Language("vi", "Vietnamese"), 215 | Language("vun", "Vunjo"), 216 | Language("wae", "Walser"), 217 | Language("cy", "Welsh"), 218 | Language("fy", "Western Frisian"), 219 | Language("wo", "Wolof"), 220 | Language("xh", "Xhosa"), 221 | Language("yav", "Yangben"), 222 | Language("yi", "Yiddish"), 223 | Language("yo", "Yoruba"), 224 | Language("dje", "Zarma"), 225 | Language("zu", "Zulu") 226 | ) -------------------------------------------------------------------------------- /src/main/kotlin/utils/StringConvertUtil.kt: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import models.StringModel 4 | import org.w3c.dom.Element 5 | import java.awt.Desktop 6 | import java.io.File 7 | import javax.xml.parsers.DocumentBuilderFactory 8 | 9 | fun readAllStrings(xmlString: String): ArrayList { 10 | val factory = DocumentBuilderFactory.newInstance() 11 | val builder = factory.newDocumentBuilder() 12 | val document = builder.parse(xmlString.byteInputStream()) 13 | 14 | val result = arrayListOf() 15 | 16 | val stringElements = document.getElementsByTagName("string") 17 | for (i in 0 until stringElements.length) { 18 | val element = stringElements.item(i) as Element 19 | if (element.hasAttribute("name")) { 20 | val name = element.getAttribute("name") 21 | val translatable = element.getAttribute("translatable") 22 | val textContent = element.textContent 23 | val isTranslatable = !translatable.equals("false", true) 24 | result.add(StringModel(name, isTranslatable, textContent)) 25 | } 26 | 27 | } 28 | 29 | return result 30 | } 31 | 32 | 33 | fun createOutputMainFolder(folderName: String) { 34 | File("output").mkdir() 35 | File("./output/$folderName").deleteRecursively() 36 | File("./output/$folderName").mkdir() 37 | } 38 | 39 | fun createStringFolder(folderName: String, languageCode: String): File { 40 | File("./output/$folderName/values-$languageCode").mkdir() 41 | val file = File("./output/$folderName/values-$languageCode/strings.xml") 42 | if (!file.exists()) file.createNewFile() 43 | return file 44 | } 45 | 46 | fun File.stringWrite(name: String, convertedString: String, isTranslatable: Boolean = true) { 47 | if (isTranslatable) { 48 | appendText( 49 | """ 50 | $convertedString""" 51 | ) 52 | } else { 53 | appendText( 54 | """ 55 | $convertedString""" 56 | ) 57 | } 58 | } 59 | 60 | fun File.startResourcesWrite() { 61 | writeText("") 62 | } 63 | 64 | fun File.endResourcesWrite() { 65 | appendText("\n") 66 | } 67 | 68 | fun isValidXml(xmlString: String): Boolean { 69 | return try { 70 | val factory = DocumentBuilderFactory.newInstance() 71 | val builder = factory.newDocumentBuilder() 72 | builder.parse(xmlString.byteInputStream()) 73 | true 74 | } catch (e: Exception) { 75 | false 76 | } 77 | } 78 | 79 | fun openOutputFile() { 80 | val file = File("output") 81 | if (file.exists()) { 82 | if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) { 83 | Desktop.getDesktop().open(file) 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /src/main/resources/translate.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /translate.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/translate.icns -------------------------------------------------------------------------------- /translate.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/translate.ico -------------------------------------------------------------------------------- /translate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coding-Meet/String-Translator-Desktop-App/307db2a73f94119756bac9b8fc254252ded713e0/translate.png --------------------------------------------------------------------------------