Page 1 of 1

Translating a state to a different language

PostPosted: Tue Jan 13, 2015 3:40 am
by haavarda
Hi.
I am trying to do what I think is a fairly simple script.
I want to take a device state (Weather underground condition) and translate the condition to another language. Then set the new translated state to a variable.
The number of possible states is limited so I think this will be a list with several if arguments. I am however not sure how the syntax should be. Any suggestions?

Håvard

Re: Translating a state to a different language

PostPosted: Tue Jan 13, 2015 3:56 am
by autolog
Probably easiest to set up a python dictionary, something like e.g.:
Code: Select all
translateDict = {'Hot': 'Chaud', 'Cold': 'Froid'}   # French translation (after a fashion!)

translateFrom = 'Cold'  # For example, the value from Weather Underground
translateTo = translateDict.get(translateFrom, 'No translation available')  # Value to move into Indigo variable
indigo.variable.updateValue(12345678, value=translateTo)  # Update Indigo Variable
If the translation isn't available you will get the 'No translation available' text returned. Replace the 12345678 with the id of your variable and the No translation available with your preferred text.

Tested and does work :)

EDIT: Added in Indigo variable update, added in more comments and tested it :)

Re: Translating a state to a different language

PostPosted: Tue Jan 13, 2015 5:02 am
by haavarda
autolog wrote:
Probably easiest to set up a python dictionary, something like e.g.:
Code: Select all
translateDict = {'Hot': 'Chaud', 'Cold': 'Froid'}   # French translation (after a fashion!)

translateFrom = 'Cold'  # For example, the value from Weather Underground
translateTo = translateDict.get(translateFrom, 'No translation available')  # Value to move into Indigo variable
indigo.variable.updateValue(12345678, value=translateTo)  # Update Indigo Variable
If the translation isn't available you will get the 'No translation available' text returned. Replace the 12345678 with the id of your variable and the No translation available with your preferred text.

Tested and does work :)

EDIT: Added in Indigo variable update, added in more comments and tested it :)


Verry good!
I think this is exactly what I was hoping for.
Can the "translateFrom" point to a device value?

Håvard

Re: Translating a state to a different language

PostPosted: Tue Jan 13, 2015 6:42 am
by autolog
Apologies for the delay in replying - I had to install Dave's Weather Underground plugin to be able to test the translation (Thanks Dave :D)

The new example code is as follows:
Code: Select all
translateDict = {'Hot': 'Chaud', 'Cold': 'Froid','Partly Cloudy': 'Partiellement Nuageux'}   # French translation (after a fashion! )

translateFrom = indigo.devices[12345678].states['conditions1']  # A state 'conditions1' from the Weather device
translateTo = translateDict.get(translateFrom, 'Traduction non disponible')  # Translated value else 'Translation not available' (in french!)

indigo.variable.updateValue(98765432, value=translateTo)

As before substitue 12345678 for you weather device and 98765432 for your variable

Hope this helps :)

Re: Translating a state to a different language

PostPosted: Tue Jan 13, 2015 6:49 am
by DaveL17
Hello and thanks!

I just posted a reply on the WUnderground forum. Norwegian is supported natively so there may be minimal additional work required.

Let me know how I can help.

Dave

Re: Translating a state to a different language

PostPosted: Tue Jan 13, 2015 7:06 am
by haavarda
Thank you for your help with the script Jon. I missed that the plugin already support different language.

Thanks again for your help! :)

Re: Translating a state to a different language

PostPosted: Tue Jan 13, 2015 7:13 am
by autolog
No Problem :)

At least it got me (finally) to install the Weather Underground plugin :D

Re: Translating a state to a different language

PostPosted: Tue Jan 13, 2015 7:16 am
by DaveL17
Enjoy the plugin Jon.

Please let me know what you think. Always trying to improve it.

Dave