Skip to content

Commit

Permalink
Version 4.12.0
Browse files Browse the repository at this point in the history
 * FEATURE - Specialized plugin translation support. Can now read text translation files that are only used for specific plugins
 * FEATURE - Proper IMGUI support in Unity 2018 and 2019+
 * MISC - Changed guidance on IMGUI redistribution
 * MISC - Changed the way output text is determined when multiple text parsers are involved in the translation (now priority based rather than first come first serve)
 * MISC - Removed feature listening to text changed event from external translation plugins
  • Loading branch information
randoman committed Jul 20, 2020
1 parent 0ddf6e0 commit f2eb358
Show file tree
Hide file tree
Showing 46 changed files with 2,024 additions and 733 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
### 4.11.4
### 4.12.0
* FEATURE - Specialized plugin translation support. Can now read text translation files that are only used for specific plugins
* FEATURE - Proper IMGUI support in Unity 2018 and 2019+
* MISC - Changed guidance on IMGUI redistribution
* MISC - Changed the way output text is determined when multiple text parsers are involved in the translation (now priority based rather than first come first serve)
* MISC - Removed feature listening to text changed event from external translation plugins

### 4.11.4
* MISC - Allow using separate service endpoint for google. Use to circumvent GFWoC
* BUG FIX - Fix bug with scene scan that could sometimes fail in certain versions of Unity

Expand Down
78 changes: 57 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ EnableNGUI=True ;Enable or disable NGUI translation
EnableTextMeshPro=True ;Enable or disable TextMeshPro translation
EnableTextMesh=False ;Enable or disable TextMesh translation
EnableIMGUI=False ;Enable or disable IMGUI translation
AllowPluginHookOverride=True ;Allow other text translation plugins to override this plugin's hooks

[Behaviour]
MaxCharactersPerTranslation=200 ;Max characters per text to translate. Max 1000.
Expand Down Expand Up @@ -475,7 +474,7 @@ A: For now, additional support for services that does not require some form of a
## 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.

This may seem like a nice feature to have enabled by default but **never redistribute the mod with this enabled**. The reason here being that IMGUI has a very spammy nature. This does not mean that IMGUI in general will spam the endpoint, just that it is more likely to cause spam (and therefore cause the plugin to shutdown).
It is also possible to provide plugin-specific translations. See next section.

## Manual Translations
When you use this plugin, you can always go to the file `Translation\{Lang}\Text\_AutoGeneratedTranslations.txt` (OutputFile) to edit any auto generated translations and they will show up the next time you run the game. Or you can press (ALT+R) to reload the translation immediately.
Expand All @@ -486,6 +485,62 @@ In this context, the `Translation\{Lang}\Text\_AutoGeneratedTranslations.txt` (O

In some ADV engines text 'scrolls' into place slowly. Different techniques are used for this and in some instances if you want the translated text to be scrolling in instead of the untranslated text, you may need to set `GeneratePartialTranslations=True`. This should not be turned on unless required by the game.

### Plugin-specific Manual Translations
Often you may want to provide translations for other plugins that are not naturally translated. This is obviously also possible with this plugin as described in the previous section. But what if you want to provide translations that should be specific to that plugin because such translation would conflict with a different plugin/generic translation?

In order to add plugin-specific translations, simply create a `Plugins` direcetory in the text translation `Directory`. In this directory you can create a new directory for each plugin you want to provide plugin-specific translations for. The name of the directory should be the same as the dll name without the extension (.dll).

Within this directory you can create translations files as you normally would. In addition you can add the following directive in these files:

```
#enable fallback
```

This will allow the plugin-specific translations to fallback to the generic/automated translations provided by the plugin. It does not matter which translation file this directive is placed it and it only need to be added once.

As a plugin author it is also possible to embed these translation files in your plugin and register them through code with the following API:

```csharp
/// <summary>
/// Entry point for manipulating translations that have been loaded by the plugin.
///
/// Methods on this interface should be called during plugin initialization. Preferably during the Start callback.
/// </summary>
public static class TranslationRegistry
{
/// <summary>
/// Obtains the translations registry instance.
/// </summary>
public static ITranslationRegistry Default { get; }
}

/// <summary>
/// Interface for manipulating translation that have been loaded by the plugin.
/// </summary>
public interface ITranslationRegistry
{
/// <summary>
/// Registers and loads the specified translation package.
/// </summary>
/// <param name="assembly">The assembly that the behaviour should be applied to.</param>
/// <param name="package">Package containing translations.</param>
void RegisterPluginSpecificTranslations( Assembly assembly, StreamTranslationPackage package );

/// <summary>
/// Registers and loads the specified translation package.
/// </summary>
/// <param name="assembly">The assembly that the behaviour should be applied to.</param>
/// <param name="package">Package containing translations.</param>
void RegisterPluginSpecificTranslations( Assembly assembly, KeyValuePairTranslationPackage package );

/// <summary>
/// Allow plugin-specific translation to fallback to generic translations.
/// </summary>
/// <param name="assembly">The assembly that the behaviour should be applied to.</param>
void EnablePluginTranslationFallback( Assembly assembly );
}
```

### Substitutions
It is also possible to add substitutions that are applied to found texts before translations are created. This is controlled through the `SubstitutionFile`, which uses the same format as normal translation text files, although things like regexes are not supported.

Expand Down Expand Up @@ -784,25 +839,6 @@ If `TextureHashGenerationStrategy=FromImageData` is specified, only a single has
## Integrating with Auto Translator
*NOTE: Everything below this point requires programming knowledge!*

### Implementing a dedicated translation component
As a mod author implementing a translation plugin, you are able to, if you cannot find a translation to a string, simply delegate it to this mod, and you can do it without taking any references to this plugin.

Here's how it works and what is required:
* You must implement a Component (MonoBehaviour for instance) that this plugin is able to locate by simply traversing all objects during startup.
* On this component you must add an event for the text hooks you want to override from XUnity AutoTranslator. This is done on a per text framework basis. The signature of these events must be: Func<object, string, string>. The arguments are, in order:
1. The component that represents the text in the UI. (The one that probably has a property called 'text').
2. The untranslated text
3. This is the return value and will be the translated text IF an immediate translation took place. Otherwise it will simply be null.
* The signature for each framework looks like:
1. UGUI: public static event Func<object, string, string> OnUnableToTranslateUGUI
2. TextMeshPro: public static event Func<object, string, string> OnUnableToTranslateTextMeshPro
3. NGUI: public static event Func<object, string, string> OnUnableToTranslateNGUI
3. IMGUI: public static event Func<object, string, string> OnUnableToTranslateIMGUI
3. TextMesh: public static event Func<object, string, string> OnUnableToTranslateTextMesh
* Also, the events can be either instance based or static.

Be aware that if you do this, that the hooking functionality of the Auto Translator itself will be disabled. So you are entirely responsible for implementing the required hooks for the overriden text framework.

### Implementing a plugin that can query translations
As a mod author, you may want to query translations from the plugin. This easily done, take a look at the example below.

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 "4.11.4";
return "4.12.0";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.11.4</Version>
<Version>4.12.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit f2eb358

Please sign in to comment.