Translating a state to a different language

Posted on
Tue Jan 13, 2015 3:40 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Translating a state to a different language

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

Håvard

Posted on
Tue Jan 13, 2015 3:56 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Translating a state to a different language

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 :)

Posted on
Tue Jan 13, 2015 5:02 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Translating a state to a different language

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

Håvard

Posted on
Tue Jan 13, 2015 6:42 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Translating a state to a different language

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 :)

Posted on
Tue Jan 13, 2015 6:49 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Translating a state to a different language

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

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jan 13, 2015 7:06 am
haavarda offline
User avatar
Posts: 702
Joined: Aug 18, 2012
Location: Norway

Re: Translating a state to a different language

Thank you for your help with the script Jon. I missed that the plugin already support different language.

Thanks again for your help! :)

Håvard

Posted on
Tue Jan 13, 2015 7:13 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Translating a state to a different language

No Problem :)

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

Posted on
Tue Jan 13, 2015 7:16 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Translating a state to a different language

Enjoy the plugin Jon.

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

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests