Alpha script.LibreTranslate
#1
Very basic translation proof of concept addon using https://github.com/LibreTranslate/LibreTranslate which offers online (paid, or free mirrors) as well as option to run your own local server.

This addon will work with any of those options.


Kodi File Manager Source:
https://kcook98765.github.io/repository.kcook98765/

Direct ZIP Install:
https://github.com/kcook98765/repository...-1.0.2.zip


Once repository is installed, you can install the translation "Program addon" LibreTranslate


It is very basic, but has settings :

1) to adjust server (uses open mirror url by default)
2) Api key (not needed for a free mirror, otherwise can add one for paid subscription or for free local server install)
3) Language to translate "to" (it auto detects language)

I tested in a basic way, in skin under <window> for the video info details window, I added:

<onload>RunScript(script.LibreTranslate,'hola')</onload>

(note 'hola' is just a sample of the text to translate, you should be able to use an $INFO[] or similar variable to send to translation.

Then in an area of the skin where display of text occurs, I added:


$INFO[Window(Home).Property(libreTranslate_text)]

This "property" is where your translated (or server error) text will be available.
Reply
#2
@kcook_shield
Perfect, it works.
But if translate 2 different texts, from 2 different labels, how is it possible to return the 2 translated texts?

Example:

xml:
<onload>RunScript(script.LibreTranslate,$INFO[ListItem.Genre])</onload>
<onload>RunScript(script.LibreTranslate,$INFO[ListItem.Country])</onload>

<item>
   <label>$LOCALIZE[515]:</label>
   <label2>$INFO[Window(Home).Property(libreTranslate_text)]</label2>
   <visible>!String.IsEmpty(ListItem.Genre)</visible>
</item>
<item>
   <label>$LOCALIZE[516]:</label>
   <label2>$INFO[Window(Home).Property(libreTranslate_text)]</label2>
   <visible>!String.IsEmpty(ListItem.Country)</visible>
</item>

This way obviously doesn't work, so i was wondering if it was possible to send 2 or more texts and return them in 2 or more variables?


Like something like this:

xml:
<item>
   <label>$LOCALIZE[515]:</label>
   <label2>$INFO[Window(Home).Property(libreTranslate_text)]</label2>
   <visible>!String.IsEmpty(ListItem.Genre)</visible>
</item>
<item>
   <label>$LOCALIZE[516]:</label>
   <label2>$INFO[Window(Home).Property(libreTranslate_text2)]</label2>
   <visible>!String.IsEmpty(ListItem.Country)</visible>
</item>


Thank you for your support 🙏
If i helped you, you can thank me with a thumbs up 👍 below, thanks 🙏.
Kodi 20.x stable release | Skin Confluence (by Jezz_X)
I like editing skins ❤
Reply
#3
That would be moving more towards skin helper service level of interaction.  Maybe pass an additional optional argument default to None with the preferred window property text which would be appended to the property key name.

scott s.
.
Reply
#4
@scott967 I don't think I understand what to do, I think it is aimed at @kcook_shield, however if it can be done it would be really useful, otherwise this addon would be very limited to a single variable/label.
If i helped you, you can thank me with a thumbs up 👍 below, thanks 🙏.
Kodi 20.x stable release | Skin Confluence (by Jezz_X)
I like editing skins ❤
Reply
#5
@"alberto1998" 

I have made a change to allow multiple translations.

See version 0.0.7 at:

https://github.com/kcook98765/script.LibreTranslate


Update: V 0.0.7 :
Added ability to send parameters to allow multiple calls and specify where to store results.
for example, can call twice in a skin:

RunScript(script.LibreTranslate,q=hola,property=a)
RunScript(script.LibreTranslate,q=adiós,property=b)

q=hola and q=adiós are static text strings, but could use $INFO[] like:

RunScript(script.LibreTranslate,q=$INFO[ListItem.Label],property=a)
RunScript(script.LibreTranslate,q=$INFO[ListItem.Genre],property=b)

After calling those, you can access the results using the "property" identifier sent in the RunScript via property name that always starts with "libreTranslate_" followed by the "property" you sent (a and b in example above, but name as you wish):

$INFO[Window(Home).Property(libreTranslate_a)]

$INFO[Window(Home).Property(libreTranslate_b)]
Reply
#6
@kcook_shield

Perfect, it works great.

It takes a 2 sec delay before it returns the translated text, as it did before the update, but I think it's normal since it has to receive the text, send it to the script, and then return it.

{ ps: in the update post you missed an extra parenthesis, so it would be correct: }
xml:
RunScript(script.LibreTranslate,q=$INFO[ListItem.Label],property=a)


Thank you so much for your work, really useful and appreciated ❤🙏
If i helped you, you can thank me with a thumbs up 👍 below, thanks 🙏.
Kodi 20.x stable release | Skin Confluence (by Jezz_X)
I like editing skins ❤
Reply
#7
@"alberto1998" 

Glad it works for you.

The delay is almost entirely because this script has to call a sever, send data, wait on processing and get the translated data back.

If you were to setup a local copy of the server from https://github.com/LibreTranslate/LibreTranslate (and change the Addon settings to point to it), it would likely be much faster (as the server would be local).

Another way to speed it up a bit would be to use a cache system (could be added to this addon), this would then still have the initial slow response, but if you then call it again, it would see the cache already has data and it could just use that data to load, skipping the server call and be very fast (well under a second).

I could look into adding a cache (using script.module.simplecache)  to this addon to automatically cache such data.
Reply
#8
@"alberto1998" 

Version 0.0.8 now uses simplecache. First lookup for a given text (does not matter what "property" you use, or even if same movie, etc) will take the same amount of time, but then if you lookup the same text again,it should pull from an internal cache and be much faster.

Currently the cache is set for 30 days, I could see about adding a setting to control the cache length, but 30 sounded good to start with (since translations should not change often).

If the lookup fails for some reason, the cache will not be used. If it works again later, then cache would be setup and used.
Reply
#9
@kcook_shield

I think a local copy of the server would be the best option. I hope that with the cache option it will not fill the memory too much.
How can i make myself a local copy of the server?
and where should I go (exactly) to change the add-on call code?


Thanks for the support 🙏
If i helped you, you can thank me with a thumbs up 👍 below, thanks 🙏.
Kodi 20.x stable release | Skin Confluence (by Jezz_X)
I like editing skins ❤
Reply
#10
@"alberto1998" 

The cache setup uses a popular (used in many addons) process that stores data on your hard drive (or ssd), so no effect on actual Memory, and unless you are doing a huge amount of translations , the hard drive storage is not going to be an issue either.

You would follow instructions at https://github.com/LibreTranslate/LibreTranslate under "Install and run" section, where there are options for Windows via docker, or Ubuntu, or can build your own. it all depends on your equipment available and ability to set it up per their instructions.

As for the setup of a local server, if you do that, then you would just navigate to the Addon Setting page , where you would see options for:

1) API translation url
(currently it is set to an existing free mirror, if you setup a local server, then change this url to the "translate" url for your server.

2) API key
(currently blank, as not enforced for free mirrors, but if you setup your own server, you might, or maybe not, need to setup an API key also, which you'd place here)

4) Language to translate to
(Default is set to English)
Reply
#11
@kcook_shield

Yes, I meant just in the local memory (ROM), the ram is not a problem since I have 3gb.

Can I ask you if it is possible to install the local server on android (11), inside the device (I have an nvidia shield tv pro) instead of installing it in windows or linux environment?
Using the shield can I host the local server directly inside the shield, or is it not possible and I have to use a windows device?
(just to avoid using other devices, I use kodi and this addon inside the shield)


Thanks for your help
If i helped you, you can thank me with a thumbs up 👍 below, thanks 🙏.
Kodi 20.x stable release | Skin Confluence (by Jezz_X)
I like editing skins ❤
Reply
#12
@"alberto1998" 

It might be possible to install on shield, though I do not know for sure and have not tried it.

You would have to get python installed somehow on the shield, then you could use the "pip install" method as noted at https://github.com/LibreTranslate/LibreTranslate

You might need to reach out to them or others with how to go about it.

But also, I am unsure of the resource overhead that running on such a device might be (memory / storage usage).

Another option would be to use a Raspberry PI  which should easily run this (and most any other software) . It is very compact, and a very low power device which can even run kodi.
Reply
#13
(2022-10-25, 23:00)kcook_shield Wrote: @"alberto1998" 

Version 0.0.8 now uses simplecache. First lookup for a given text (does not matter what "property" you use, or even if same movie, etc) will take the same amount of time, but then if you lookup the same text again,it should pull from an internal cache and be much faster.

Currently the cache is set for 30 days, I could see about adding a setting to control the cache length, but 30 sounded good to start with (since translations should not change often).

If the lookup fails for some reason, the cache will not be used. If it works again later, then cache would be setup and used.

How about a local SQlite database with a refresh field, similar how the textures cache works in Kodi ?  It would be fast, scalable and you can control the age / refresh timer with a setting.  It would persist past reboots.  I use this technique for many things in some of my addons.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#14
@jbinkley60 

Thanks for the suggestion, and if the needs for this grows, I will look into a dedicated cache DB.

However, the existing use of script.module.simplecache uses an sqlite DB already, and also carries over between reboots and has a setting for the duration to keep the cache (currently hard coded at 30 days in my addon, but I could offer up a setting for this value).

I will entertain the switch to a dedicated DB based on feedback/usage.
Reply
#15
@kcook_shield

ok, thanks for the help.

I think this component will be used a lot once it is known.
I hope you will continue to support him 🙏
If i helped you, you can thank me with a thumbs up 👍 below, thanks 🙏.
Kodi 20.x stable release | Skin Confluence (by Jezz_X)
I like editing skins ❤
Reply

Logout Mark Read Team Forum Stats Members Help
script.LibreTranslate0