Giter Club home page Giter Club logo

funnysaltyfish / transtation-kmp Goto Github PK

View Code? Open in Web Editor NEW
48.0 2.0 6.0 46.44 MB

A translation app on Android/Desktop built by Kotlin Multiplatform + Compose Multiplatform, enjoy amazing experience with LLMs' support

Home Page: https://www.funnysaltyfish.fun/trans?source=github

License: GNU General Public License v3.0

Kotlin 73.27% Java 26.68% JavaScript 0.05%
compose-desktop compose-multiplatform jetpack-compose kotlin-multiplatform large-language-models translation

transtation-kmp's Introduction

Transtation

"Transtation" is the combination of "Translate" and "Station", it's an easy-to-use and powerful translation software for Android/Desktop(JVM), based on Kotlin Multiplatform + Compose Multiplatform.

  • Translate one item using multiple engines (Bing, Google, Baidu, Tencent) at the same time
  • Use several advanced Large Language Models (LLMs), like ChatGPT, GPT-4, ChatGLM, Qwen to translate
  • Or translate by chatting with LLMs
  • You can even translate very long text in Long Text Translation page using LLMs
  • Support plugin development, download, update, import, export, etc. with high scalability
  • Image translation is also supported, several engines are available as well
  • Screen translation is supported, floating window/regional screenshot translation/full-screen screenshot translation are all supported
  • Customize your theme, language, engines, etc.
  • ALL YOU NEED ABOUT TRANSLATION

Due to the time limit, some of the features are not available in Desktop version yet, but they will be added in the future.

Introduction

This software is a translation software which mainly serves for Chinese users right now. It is also a open-source project which can be referred to when learning Jetpack Compose or Compose Multiplatform. The project is the KMP version of Transtation, which has been maintained for 4 year in Android platform.

The following are the features of this application:

  • Kotlin Multiplatform + Compose Multiplatform + MVVM + Kotlin Coroutine + Flow + SqlDelight
  • Multi-module design, with separation between the common module and the project module
  • Supports synchronized translation with multiple engines, and supports plugin development, download, update, import, export, etc. with high scalability
  • Makes full use of the Kotlin language features, such as lazy loading, class proxy, Coroutine, Flow, sealed classes, extension methods, extension properties, and reflection, etc.
  • Based on Rhino JS, it designs and implements a complete JavaScript plugin loading, running, and debugging environment, providing one-stop support for plugin development
  • Adapts to Android11 file permissions, adapts to bilingual, dark mode, landscape/tablet pages, and develops, uses and publicly releases four open source libraries

The application gradually adapts to Android13, including:

  • Supports setting the application language separately
  • Supports Monet icon

You can get the latest version from the following ways:

If you want to read the code, I recommend that you start from the main Activity

If you find it helpful, welcome to star!

Screenshot

Screen Recording

v2.8.0 (2024/01/15)

TranstationKMP_intro_x264.mp4

Running Screenshot

Android

UI v4:

Old UI v3
Screenshot Screenshot
Desktop
  • Desktop version is still under development, the UI might change a lot in the future.
Screenshot Screenshot

For Developers

If you're a developer and want to view the code or build the application, the following might be helpful:

IDE Experience

In the initial days of development, I tried using Fleet, Android Studio, and IDEA multiple times to develop this application. In the end, I continued using Android Studio. Its development experience is essentially consistent with IDEA, and Desktop applications can be run directly by clicking a small button. The reasons for not choosing the other two are:

  • Fleet: Currently, it seems a bit rudimentary, and it's challenging to bring up various windows (cannot be kept resident), lacks AI completion.
  • IDEA: The automatically generated expect/actual positions are very strange. For example, on the Android side, it displays both androidMain and kotlin.androidMain. Choosing the former has no effect, and choosing the latter generates a file with a name like: Xxx.android.commonMain.kotlin.kt, which is not very reasonable.

Migration Process

I recorded some of the migration process, I suggest you read it if you're interested in it. Because it is too long, I put it to another file:

Source Code Overview

As an open-source project, you can learn about it from the following aspects:

Code Style

In terms of code organization, the code here doesn't strictly follow Google's best practices. If you want to pursue elegant code, you can refer to Google's official NowInAndroid project. However, in terms of actual usage, that project's pursuit of unified data flow has led to suboptimal user experience (for example, in the version I experienced, clicking on "Favorite" in any list item would trigger an upstream flow update, refreshing the entire list. This would cause the list to scroll back to the top when you click a favorite button, which clearly doesn't align with the actual user experience).

The code is written following this rule: Composable + ViewModel. Simple logic is implemented directly in Composable, while more complex logic is implemented in ViewModel. For the sake of convenience, the State inside the ViewModel has not adopted the "internal MutableState + externally exposed State" strategy. Instead, all States are mutable, and some are directly accessed through vm.xxx.

However, there are still some basic cleanliness aspects, such as naming conventions, code indentation, and Kotlin-style programming. The main ViewModel files and Composable pages, under AS inspection, achieve full green for the most part, with the majority of yellow Lint warnings ranging from 1 to 5, mostly relating to unused TAG variables or unused functions.

Modules
  • composeApp: the main translation page
  • base-kmp: the basic module, defining basic Beans, and introducing third-party modules in API form for use by other parts
  • code-editor: the code editor page
  • login: the login and registration page
  • ai: LLM related logics
  • android-code-editor: editor, language-base, language-universal: code editor View from the open-source project sora-editor
  • buildSrc: dependency version management
Preparation Before Running
  • You need to use Android Studio version Flamingo or higher, the newest stable version is highly recommended.

  • For security reasons, the open-source part does not include the signing.properties file containing signature information. If you need to build a release version, please add this file yourself.

    • signing.properties

    • located in the root directory

      // If you need to build a release package, please add this file yourself in the project root directory
      /**
       *  STORE_FILE=yourAppStroe.keystore
          STORE_PASSWORD=yourStorePwd
          KEY_ALIAS=yourKeyAlias
          KEY_PASSWORD=yourAliasPwd
       */
  • For Chinese developers, due to the preferred repositories are Google and Maven, you may need to configure the proxy to download the dependencies. Or you can modify the repositories in build.gradle.kts and settings.gradle.kts and move the Chinese mirrors to the top.

If you are unable to run it on the latest stable version of Android Studio and the correct Gradle version, and you have confirmed that it is not due to your own issues, feel free to open an issue and ask. It's possible that I missed some files when committing to Git. I will respond as soon as I see it.

Acknowledgments

  • UI design (v3) referenced from 酷安@江戸川コナン (authorized)
  • UI design (V4) and promotional graphics from 酷安@松川吖
  • Thank you to all the friends who have sponsored the project!
  • Thank you to all the contributors!

Contributors ✨

Star History

Star History Chart

If this project is helpful to you, welcome to Star it~

transtation-kmp's People

Contributors

funnysaltyfish avatar moriafly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

transtation-kmp's Issues

Share common configs between `build.gradle.kts` of various modules

Now, all the configs (build.gradle.kts) in different modules are created by copy-and-paste, however, there are a lot of common configs that can be shared (like buildkonfig, libres, sqldelight...). I've tried a lot of time implementing so, but the result is disappointing.

If you're familiar with this, I would be very appreciated that if you could help. Thanks a lot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.