Giter VIP home page Giter VIP logo

Comments (7)

JarvyJ avatar JarvyJ commented on August 19, 2024

Hello @oerkel47! I think I have a solution for the HA API returning states/attributes in English. Since it only affects the Home Assistant component, I've created an api_translations folder with the languages' translations that come back from the HA API (in a new branch - #279)

The idea being that any English response that comes back from the API indicating a state (like on or off) is defined in the api_translations/[language].json file. This gets autoloaded by the Home Assistant component and is setup in the HomeAssistant component.

In all of the domain-specific controller and their language files it can be accessed with self.ha.api_translation. So in switch/de.py, you could use self.ha.api_translations["on"] and it would return an.

I kinda like the idea of having all the responses from the API translated in the same place. If you want to try out the branch and let me know how it goes that would be great! I tried it out a bit and I hope it'll be useful overall.

from homeintent.

oerkel47 avatar oerkel47 commented on August 19, 2024

Thanks @JarvyJ, I will try it out soon.

from homeintent.

oerkel47 avatar oerkel47 commented on August 19, 2024

Wouldn't it be a good idea to directly translate the translatable entries inside the response dict inside the base class? Would take the work from the translators while also keeping the language specific code tidy.

response = self._toggle_light(light)
response["state"] = self.ha.api_translation[response["state"]]

This works, but looks ugly.

from homeintent.

JarvyJ avatar JarvyJ commented on August 19, 2024

Oh, I like that idea! It'll make it a lot nicer for translators. I'll see if I can get it worked in today along with a workaround for #274

from homeintent.

JarvyJ avatar JarvyJ commented on August 19, 2024

The branch has been updated!

So I ended up doing the translation work in the Home Assistant api code. This way any get_entity call that has a state attribute will get translated with the json file.

I've also made the get_entity to take in the response from call_service and check if it's an empty list, perform the delay, and then return. This should solve the issue in #274.

I'll do a bit more testing on my end, and if it seems good for you, we can merge and go from there!

from homeintent.

oerkel47 avatar oerkel47 commented on August 19, 2024

Regarding the translation: my first tests worked without issue, but have not done many. Nice work!

from homeintent.

JarvyJ avatar JarvyJ commented on August 19, 2024

closed with #279

from homeintent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.