Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Translate UI element text
#1
Gets UI element text and translates with Google Cloud Translation API. Displays the result as a tooltip.

Download and import the attached file. To import:
- Menu File -> Export, import -> Import .zip.
- Or drag and drop.

Language codes


Attached Files
.zip   Translate UI element text.zip (Size: 17.2 KB / Downloads: 25)
#2
Translates the control text at the mouse pointer, Set the trigger by pressing the Ctrl key twice, Is this possible? Smile
#3
thanks, the code Works well

Do I have to create a separate script file?
How to put the code into file @Triggers and toolbars -> Triggers -> Hotkey triggers.cs  , 
I tried without success
#4
Menu TT -> Other triggers. It opens a file with examples.
In that file add this somewhere inside the class:

Code:
Copy      Help
    [Triggers]
    void KeyboardHookTriggers() {
        WindowsHook.Keyboard(k => {
            var a = _lastKeys ??= new();
            if (a.Count > 15) a.RemoveAt(a.Count - 1);
            a.Insert(0, new(k.IsUp, k.Key, k.Mod, k.vkCode, k.scanCode, k.IsExtended, k.IsInjected, k.IsAlt, k.time));
            
            //trigger LCtrl*2
            if (k.vkCode == KKey.LCtrl) {
                if (k.IsUp && a.Count >= 4 && a[1].vkCode == k.vkCode && !a[1].isUp && a[2].vkCode == k.vkCode && a[2].isUp && a[3].vkCode == k.vkCode && !a[3].isUp && a[1].time - a[3].time < 500 && (a.Count == 4 || a[4].vkCode != k.vkCode || a[3].time - a[4].time > 500)) {
                    //print.it("LCtrl*2");
                    script.run("Translate UI element text.cs");
                }
            }

            
            //Add other triggers here.
            //    To block the key event: k.BlockEvent();
            
            //Note: this function must be as fast as possible. Slow code here will make kayboard input slow.
            //    If need slow code, put it in other script or thread, and here just start the script or thread.

        });
    }

    
    record _KeyEvent(bool isUp, KKey key, KMod mod, KKey vkCode, uint scanCode, bool isExtended, bool isInjected, bool isAlt, int time);
    List<_KeyEvent> _lastKeys; //max 16 previous key events, starting from the most recent, including current event
#5
Now QTranslate can translate UI elements too. Older versions translated only through Ctrl+C. But it has high-DPI problems.
#6
thanks
#6 The code works fine

QTranslate It will pop up, which is not very convenient
#7
It's a bit strange, some pages on the forum can't be used by Google Translate. The translation did not take effect  Huh

e.g:
https://www.libreautomate.com/forum/show...1#pid36131
#8
Tested, translates that forum page. Maybe depends on language, I don't know.
#9
Only some web pages cannot be translated

[Image: abc.gif]
#10
Don't know. I translate to Lithuanian and it works.

Maybe browser caching problems. Try to hard-reload the page (Ctrl+F5).
#11
Still doesn't work, I'll try again in a few days,
Thanks for your help


Forum Jump:


Users browsing this thread: 1 Guest(s)