Skip to content

Commit

Permalink
* FEATURE - Support legitimate Bing translate API (requires key)
Browse files Browse the repository at this point in the history
 * FEATURE - Documented custom endpoint
 * BUG FIX - Fixed bug in older versions of the Unity engine where the plugin would crash on startup due to missing APIs in relation to the SceneManagement namespace
 * BUG FIX - Fixed bug that could happen in Utage-based games, that would cause dialogue to sometimes be cut off mid-sentence
 * BUG FIX - Incorrect handling of 'null' default values in configuration
 * BUG FIX - Various other minor fixes
 * MISC - Added configuration option to support ignoring texts starting with certain characters, IgnoreTextStartingWith
 * MISC - Template reparation for IMGUI translations
 * MISC - Big update to README file to fully describe the features of the plugin
  • Loading branch information
randoman committed Jan 11, 2019
1 parent e0d1134 commit 571c8cf
Show file tree
Hide file tree
Showing 28 changed files with 673 additions and 116 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
### 2.16.0
### 2.17.0
* FEATURE - Support legitimate Bing translate API (requires key)
* FEATURE - Documented custom endpoint
* BUG FIX - Fixed bug in older versions of the Unity engine where the plugin would crash on startup due to missing APIs in relation to the SceneManagement namespace
* BUG FIX - Fixed bug that could happen in Utage-based games, that would cause dialogue to sometimes be cut off mid-sentence
* BUG FIX - Incorrect handling of 'null' default values in configuration
* BUG FIX - Various other minor fixes
* MISC - Added configuration option to support ignoring texts starting with certain characters, IgnoreTextStartingWith
* MISC - Template reparation for IMGUI translations
* MISC - Big update to README file to fully describe the features of the plugin

### 2.16.0
* FEATURE - Support image dumping and loading (not automatic!). Disabled by default
* BUG FIX - Fixed toggle translation which was broken in 2.15.4
* BUG FIX - Updated TKK retrieval logic
Expand Down
111 changes: 89 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,89 @@
# XUnity Auto Translator

## Index
* [Notice](#notice)
* [Introduction](#introduction)
* [Translators](#translators)
* [Text Frameworks](#text-frameworks)
* [Plugin Frameworks](#plugin-frameworks)
* [Configuration](#configuration)
* [Key Mapping](#key-mapping)
* [Installation](#installation)
* [Translating Mods](#translating-mods)
* [Manual Translations](#manual-translations)
* [Regarding Redistribution](#regarding-redistribution)
* [Texture Translation](#texture-translation)
* [Integrating with Auto Translator](#integrating-with-auto-translator)

## Notice
The latest version (2.16.0+) now also supports basic image loading/dumping. These are not automatically translated and the feature is disabled by default.

This feature is primarily meant for games with little to no mod support to enable full translations without needing to modify resource files.

If you are going to make use of this feature, please make sure you read and understand the [Texture Translation](#texture-translation) section!

## Introduction
This is a plugin that is capable of using various online translators to provide on-the-fly translations for various Unity-based games.

It does (obviously) go to the internet, in order to provide the translation, so if you are not comfortable with that, don't use it.

Oh, and it is also capable of doing some basic image loading/dumping. Go to the [Texture Translation](#texture-translation) section to find out more.

If you intend on redistributing this plugin as part of a translation suite for a game, please read [this section](#regarding-redistribution).

## Translators
The supported online translators are:
* [GoogleTranslate](https://anonym.to/?https://translate.google.com/), based on the online Google translation service. Does not require authentication.
* No limitations, but unstable.
* [GoogleTranslateLegitimate](https://anonym.to/?https://cloud.google.com/translate/), based on the Google cloud translation API. Requires an API key.
* Provides trial period of 1 year with $300 credits. Enough for 15 million characters translations.
* [BingTranslateLegitimate](https://anonym.to/?https://docs.microsoft.com/en-us/azure/cognitive-services/translator/translator-info-overview), based on the Azure text translation. Requires an API key.
* Free up to 2 million characters per month.
* [BaiduTranslate](https://anonym.to/?https://fanyi.baidu.com/), based on Baidu translation service. Requires AppId and AppSecret.
* Not sure on quotas on this one.
* [YandexTranslate](https://anonym.to/?https://tech.yandex.com/translate/), based on the Yandex translation service. Requires an API key.
* Free up to 1 million characters per day, but max 10 million characters per month.
* [WatsonTranslate](https://anonym.to/?https://cloud.ibm.com/apidocs/language-translator), based on IBM's Watson. Requires a URL, username and password.
* Free up to 1 million characters per month.
* [ExciteTranslate](https://anonym.to/?https://www.excite.co.jp/world/english_japanese/), based on the Excite online translation service. Does not require authentication.
* No limitations, but unstable. Also very slow.
* Custom. Alternatively you can also specify any custom HTTP url that can be used as a translation endpoint (GET request). This must use the query parameters "from", "to" and "text" and return only a string with the result (try HTTP without SSL first, as unity-mono often has issues with SSL).
* Example Endpoint=http://my-custom-translation-service.net/translate
* Example Request: GET http://my-custom-translation-service.net/translate?from=ja&to=en&text=こんにちは
* Example Response (only body): Hello
* If someone is willing to implement it, this could provide support for offline translators such as ATLAS or LEC as well, since it enables the scenario where you simply run a local web server that can serve translation requests.

**Do note that if you use any of the online translators that does not require some form of authentication, that this plugin may break at any time.**

### About Authenticated Translators
If you decide to use an authenticated service *do not ever share your key or secret*. If you do so by accident, you should revoke it immediately. Most, if not all services provides an option for this.

Also, make sure you monitor the service's request usage/quotas, especially when it is being used with unknown games. This plugin makes no guarantees about how many translation requests will be sent out, although it will attempt to keep the number to a minimum. It does so by using the [spam prevention mechanisms](#spam-prevention) discussed below.

### Spam Prevention
The plugin employs the following spam prevention mechanisms:
1. When it sees a new text, it will always wait one second before it queues a translation request, to check if that same text changes. It will not send out any request until the text has not changed for 1 second. (Utage (VN Game Engine) is an exception here, as those texts may come from a resource lookup)
2. It will never send out more than 8000 requests (max 200 characters each (configurable)) during a single game session.
3. It will never send out more than 1 request at a time (no concurrency!).
4. If it detects an increasing number of queued translations (3500), the plugin will shutdown.
5. If the service returns no result for five consecutive requests, the plugin will shutdown.
6. If the plugin detects that the game queues translations every frame, the plugin will shutdown after 90 frames.
7. If the plugin detects text that "scrolls" into place, the plugin will shutdown. This is detected by inspecting all requests that are queued for translation. ((1) will genenerally prevent this from happening)
8. If the plugin consistently queues translations every second for more than 60 seconds, the plugin will shutdown.
9. For the supported languages, each translatable line must pass a symbol check that detects if the line includes characters from the source language.
10. It will never attempt a translation for a text that is already considered a translation for something else.
11. All queued translations are kept track of. If two different components that require the same translation and both are queued for translation at the same time, only a single request is sent.
12. It employs an internal dictionary of manual translations (~10000 in total) for commonly used phrases (Japanese-to-English only) to prevent sending out translation requests for these.
13. Some endpoints support batching of translations so far fewer requests are sent. This does not increase the total number of translations per session (2).
14. All translation results are cached in memory and stored on disk to prevent making the same translation request twice.

## Text Frameworks
This is an auto translation mod that hooks into the unity game engine and attempts to provide translations for the following text frameworks for Unity:
* UGUI
* NGUI
* IMGUI
* TextMeshPro
* Utage (VN Game Engine)

It does go to the internet, in order to provide the translation, so if you are not comfortable with that, don't use it.

The following text frameworks are supported.
* [UGUI](https://docs.unity3d.com/Manual/UISystem.html)
* [NGUI](https://assetstore.unity.com/packages/tools/gui/ngui-next-gen-ui-2413)
* [IMGUI](https://docs.unity3d.com/Manual/GUIScriptingGuide.html) (disabled by default)
* [TextMeshPro](http://digitalnativestudios.com/textmeshpro/docs/)
* [Utage (VN Game Engine)](http://madnesslabo.net/utage/?lang=en)

## Plugin Frameworks
The mod can be installed into the following Plugin Managers:
* [BepInEx](https://github.com/bbepis/BepInEx)
* [BepInEx](https://github.com/bbepis/BepInEx) (preferred approach)
* [IPA](https://github.com/Eusth/IPA)
* UnityInjector

Installations instructions for both methods can be found below.
Installation instructions for all methods can be found below.

Additionally it can be installed without a dependency on a plugin manager through ReiPatcher. However, this approach is not recommended if you use one of the above mentioned Plugin Managers!

Expand All @@ -43,7 +92,7 @@ The default configuration file, looks as such (2.6.0+):

```ini
[Service]
Endpoint=GoogleTranslate ;Endpoint to use. Can be ["GoogleTranslate", "GoogleTranslateLegitimate", "BaiduTranslate", "YandexTranslate", "WatsonTranslate", "ExciteTranslate", ""]. If empty, it simply means: Only use cached translations
Endpoint=GoogleTranslate ;Endpoint to use. Can be ["GoogleTranslate", "GoogleTranslateLegitimate", "BingTranslateLegitimate", "BaiduTranslate", "YandexTranslate", "WatsonTranslate", "ExciteTranslate", "*any custom http endpoint*", ""]. If empty, it simply means: Only use cached translations

[General]
Language=en ;The language to translate into
Expand All @@ -57,12 +106,13 @@ OutputFile=Translation\_AutoGeneratedTranslations.{lang}.txt ;File to insert g
EnableUGUI=True ;Enable or disable UGUI translation
EnableNGUI=True ;Enable or disable NGUI translation
EnableTextMeshPro=True ;Enable or disable TextMeshPro translation
EnableIMGUI=False ;Enable of disable IMGUI translation
EnableIMGUI=False ;Enable or disable IMGUI translation
EnableUtage=True ;Enable or disable Utage-specific translation
AllowPluginHookOverride=True ;Allow other text translation plugins to override this plugin's hooks

[Behaviour]
Delay=0 ;Delay to wait before attempting to translate a text in seconds
MaxCharactersPerTranslation=150 ;Max characters per text to translate
MaxCharactersPerTranslation=200 ;Max characters per text to translate
IgnoreWhitespaceInDialogue=True ;Whether or not to ignore whitespace, including newlines, in dialogue keys
IgnoreWhitespaceInNGUI=True ;Whether or not to ignore whitespace, including newlines, in NGUI
MinDialogueChars=20 ;The length of the text for it to be considered a dialogue
Expand All @@ -77,6 +127,7 @@ OverrideFont= ;Overrides the fonts used for texts when updati
WhitespaceRemovalStrategy=TrimPerNewline ;Indicates how whitespace/newline removal should be handled before attempting translation. Can be ["TrimPerNewline", "AllOccurrences"]
ResizeUILineSpacingScale= ;A decimal value that the default line spacing should be scaled by during UI resizing, for example: 0.80. NOTE: Only works for UGUI
ForceUIResizing=True ;Indicates whether the UI resize behavior should be applied to all UI components regardless of them being translated.
IgnoreTextStartingWith=\u180e; ;Indicates that the plugin should ignore any strings starting with certain characters. This is a list seperated by ';'.

[Texture]
TextureDirectory=Translation\Texture ;Directory to dump textures to, and root of directories to load images from
Expand All @@ -93,6 +144,9 @@ UserAgent= ;Override the user agent used by APIs requiring
[GoogleLegitimate]
GoogleAPIKey= ;OPTIONAL, needed if GoogleTranslateLegitimate is configured

[BingLegitimate]
OcpApimSubscriptionKey= ;OPTIONAL, needed if BingTranslateLegitimate is configured

[Baidu]
BaiduAppId= ;OPTIONAL, needed if BaiduTranslate is configured
BaiduAppSecret= ;OPTIONAL, needed if BaiduTranslate is configured
Expand Down Expand Up @@ -199,6 +253,19 @@ The file structure should like like this
## Translating Mods
Often other mods UI are implemented through IMGUI. As you can see above, this is disabled by default. By changing the "EnableIMGUI" value to "True", it will start translating IMGUI as well, which likely means that other mods UI will be translated.

## Manual Translations
When you use this plugin, you can always go to the file `Translation\_AutoGeneratedTranslations.{lang}.txt` (OutputFile) to edit any auto generated translations and they will show up the next time you run the game.

It is also worth noting that this plugin will read all text files (*.txt) in the `Translation` (Directory), so if you want to provide a manual translation, you can simply cut out texts from the `Translation\_AutoGeneratedTranslations.{lang}.txt` (OutputFile) and place them in new text files in order to replace them with a manual translation.

In this context, the `Translation\_AutoGeneratedTranslations.{lang}.txt` (OutputFile) will always have the lowest priority when reading translations. So if the same translation is present in two places, it will not be the one from the (OutputFile) that is used.

## Regarding Redistribution
Redistributing this plugin for various games is absolutely encouraged. However, if you do so, please keep the following in mind:
* **IMPORTANT: Distribute the _AutoGeneratedTranslations.{lang}.txt file along with the redistribution with as many translations as possible to ensure the online translator is hit as little as possible.**
* Ensure you keep the plugin up-to-date, as much as reasonably possible.
* If you use image loading feature, make sure you read [this section](#texture-translation).

## Texture Translation
From version 2.16.0+ this mod provides basic capabilities to replace images. It is a feature that is disabled by default. There is no automatic translation of these images though.

Expand Down
2 changes: 1 addition & 1 deletion src/XUnity.AutoTranslator.Patcher/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string Version
{
get
{
return "2.16.0";
return "2.17.0";
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/XUnity.AutoTranslator.Plugin.BepIn/BepInLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using XUnity.AutoTranslator.Plugin.Core;
using XUnity.AutoTranslator.Plugin.Core.Constants;

namespace XUnity.AutoTranslator.Plugin.BepIn
{
Expand All @@ -15,7 +16,7 @@ public BepInLogger()

protected override void Log( LogLevel level, string message )
{
BepInEx.Logger.CurrentLogger.Log( Convert( level ), "[XUnity.AutoTranslator] " + message );
BepInEx.Logger.CurrentLogger.Log( Convert( level ), "[XUnity.AutoTranslator " + PluginData.Version + "] " + message );
}

public BepInEx.Logging.LogLevel Convert( LogLevel level )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>2.16.0</Version>
<Version>2.17.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 571c8cf

Please sign in to comment.