Comments (7)
After reading it, I actually think solution 2 is rather elegant.
from bepisplugins.
To make a generic solution, I would like if it is possible if there was a hook for each available text framework that you use.
For instance, you could implement two events on DynamicTranslator:
public event Action<object, string> OnUnableToTranslateUGUI;
public event Action<object, string> OnUnableToTranslateTextMeshPro;
In this way, I can still handle IMGUI and NGUI text events, yeah? :)
from bepisplugins.
I've implemented my part on this branch:
https://github.com/XUnity-Plugins/XUnity.AutoTranslator/tree/feature/plugin_integration
from bepisplugins.
Hm. I am trying to create a pull request, but I am absolutely unable to build the solution, even after adding all the missing DLLs in the lib folder manually.
Do you use something special to build this project? I've tried with both VS2017 and VS2015.
from bepisplugins.
Meh, it's not like I have changed a lot. Here's my changes:
Field Section:
private static HashSet<string> untranslated = new HashSet<string>();
private static event Action<object, string> OnUnableToTranslateUGUI;
private static event Action<object, string> OnUnableToTranslateTextMeshPro;
Method Section:
public static string Translate(string input, object obj)
{
if(string.IsNullOrEmpty(input) || !ContainsJapaneseSymbols(input)) return input;
// Consider changing this! You have a dictionary, but you iterate instead of making a lookup. Why do you not use the WeakKeyDictionary, you have instead?
if (!originalTranslations.Any(x => x.Key.Target == obj)) //check if we don't have the object in the dictionary
{
//add to untranslated list
originalTranslations.Add(new WeakReference(obj), input);
}
string translation;
if (translations.TryGetValue(input, out translation))
{
return translation;
}
else if(obj is Text)
{
OnUnableToTranslateUGUI?.Invoke( obj, input );
}
else if(obj is TMP_Text)
{
OnUnableToTranslateTextMeshPro?.Invoke( obj, input );
}
// Consider changing this! You make a value lookup in a dictionary, which is really bad performance
if (!untranslated.Contains(input) && !translations.ContainsValue(input))
untranslated.Add(input);
return input;
}
public static bool ContainsJapaneseSymbols( string text )
{
// Japenese regex: [\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]
foreach( var c in text )
{
if( ( c >= '\u3040' && c <= '\u30ff' ) || ( c >= '\uff00' && c <= '\uff9f' ) || ( c >= '\u4e00' && c <= '\u9faf' ) || ( c >= '\u3400' && c <= '\u4dbf' ) )
{
return true;
}
}
return false;
}
I changed some unrelated code, and added some comments:
- I changed List untranslated to HashSet untranslated
- During the Translate method, you use the "originalTranslations" with linq instead of a lookup. This scales really poorly. Consider using a WeakDictionary. I have one of these in my repositories. That is a dictionary I adapted from a weak KEYed and VALUEed dictionary to only be weak KEYed. But you will need to make sure you prune it now and then for collected key references.
- At the end of the Translate method you make a value lookup in a dictionary, this also scales really poorly. Consider removing it. If you want to make sure you have not already translated consider having a HashSet with translated values where you can look it up in instead. You could also use a Dictionary with it as a key.
from bepisplugins.
Finally figured out what I was doing wrong. :) Testing it now.
from bepisplugins.
Good news, everyone! I managed to make it work.
Two notes:
- I had to do something fairly awkward though. I had to use an event with a return value, to handle the situation where I call SetText from my own plugin immediately, if it was cached up. That was a bug that was caused by me setting a translated text, and afterwards your plugin setting the untranslated text. :) I could not think of any other way of solving this issue, if none of the two plugins has a references to eachother.
- You should probably consider hooking into more of the text change events. If I use my plugin alone, it is better at figuring out what needs to be translated. Consider looking into which events I hook into.
I will see if I can make a pull request in a moment.
from bepisplugins.
Related Issues (20)
- [KK/HS2] - [SliderUnlocker] NullReferenceException HOT 1
- [KK] - [Capture resolution limit more than 16k] HOT 1
- [AI/HS2] - [4k DOF] HOT 2
- KK - Extended Save Format exception on 2023(latest) Steam Version KK+AfterParty HOT 2
- Screencap - allow changing of screenshot name format HOT 1
- Add a button to show a plugin hotkey list to the game's built-in F2 hotkey screen
- [HS2] - [Screenshotwithcharacard]Does character (F11 key) screenshot picture include the character card? HOT 1
- ColorCorrector - don't override bloom strength by default
- BepisPlugins r19.2 Bloom BUG HOT 2
- [KKS] - [Screencap 360 screenshot with stitching] HOT 1
- [KKS] - [Screencap 3D VR performance] HOT 2
- [KKS-Screencap 3DVR] - How do I get the front of the frame to follow the angle of the camera instead of being horizontal all the time? HOT 1
- HS2.BGMLoader.cs cann't work
- [AI/HS2] - Sideloader resolve warning spam at saving/loading studio scenes HOT 6
- [HS2] - [Screenshot CAP] Game freezing while rendering HOT 5
- HS2.targets a wrong version of BepInEx (5.4.22.0) HOT 1
- [AI] - [Sideloader doesn't work with housing mods] HOT 1
- Heelz is broen HOT 1
- [HS2] - [About tattoo mod's color] HOT 1
- [KK/KKS] - [Screencap 360 3d can't capture 8192 resolution screenshots] HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bepisplugins.