Skip to content

[v0.2] Local translation directly via the CTranslate2 library #9

@BluSpring

Description

@BluSpring

For a good while now, UnityTranslate has been unfortunately broken on many servers, instances, pretty much all of them. While I have tried to solve these issues, unfortunately there have been many different pitfalls that have prevented me from fully and properly solving them.

Over the months, despite several health challenges that have been affecting me recently, I have constantly kept looking into accomplishing one goal: Implementing local translation via CTranslate2's library.

The Issue

The translation system within UnityTranslate is reliant on a web API known as LibreTranslate, and UT downloads and launches a local instance of LibreTranslate on the server-side whenever it is needed. However, many server hosts implement a system (likely for security reasons) that directly prevents UnityTranslate from launching this local instance. Additionally, after several updates towards LibreTranslate, my fork that automatically builds an executable for servers no longer seems to be functional.

Benefits of this System

  • Improved performance
  • Decreased total download sizes
  • Entirely fixing local translation
  • Removing dependency on LibreTranslate
  • Full control over UnityTranslate's translation system

Requirements

  • Compiles for the following platforms:
    • Windows x86-64
    • macOS x86-64
    • macOS arm64
    • Linux x86-64
    • Linux arm64
  • Fully functions as a JNI library used within Java
  • Functions identically to Argos Translate / LibreTranslate's translation system

Explanation

The LibreTranslate web API uses a library created by the same developers, called Argos Translate. However, this library is written for Python, and UnityTranslate is written for the JVM. I have looked into solutions such as Jython and JEP for handling this, however neither of them are capable of handling a library such as Argos Translate. After reading through the source code of Argos Translate, I have discovered that it primarily utilizes 3 libraries:

With this knowledge in mind, I decided to look into reimplementing Argos Translate as a native library, but after attempting this in several different languages, I have kept running into several different dead ends, and I am slowly reaching a point where I'm not sure if I would even be able to work on this further.

I have tried Rust, C++ over Meson, C++ over CMake, Kotlin/Native, Zig, even Kotlin + LWJGL. I just cannot. get this to work. I'm starting to reach a point where I'm even about to learn how to use Go as well just to try to get this working. The most common issues:

  • CMake fails to be set up/imported (SentencePiece and CT2 use CMake as their build systems.)
  • MSVC/MinGW fails to compile a shared library
  • MSVC/MinGW fails to link any libraries together
  • The libraries fail to even get detected by interop, due to being written in C++
  • The header files don't even work

The closest I have gotten to getting this working was with using Rust, but in the end, I still ended up empty-handed with the CTranslate2 DLL constantly failing when loading a model. Unfortunately, CT2 was not designed to function as a Windows DLL, and I want to allow this to work on a Windows machine. I would compile it as a static .lib, however, Java is not designed to load static libraries, and as far as I am aware, I just cannot seem to get a static library to even compile alongside a shared library. So I've been stuck.

I do not want to manually port the entirety of CT2 to Rust, as I lack the time, energy, health, and understanding, to be able to do this on my own. But I am running out of options, and I am struggling to do this alone. So I need help to figure this out.

This mod is so genuinely important to so many people in the community, and I want to get to see it at its very best. I want to be able to expand this outside of just Minecraft. If you know how to do anything relating to this, or know anyone who knows how to do this, please.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions