Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation support for device automation extra fields #20567

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

farmio
Copy link
Contributor

@farmio farmio commented Apr 20, 2024

Proposed change

Add translation support for integration specific device trigger extra fields.

Core PR to allow new keys in strings.json: home-assistant/core#115892

This can be tested with a core-branch adding a new device trigger for "Sun" with some dummy extra_fields
home-assistant/core#115846

Given an integrations strings.json

{
  "device_automation": {
    "trigger_type": {
      "test_sun_trigger": "Sun trigger 🌞"
    },
    "extra_fields": {
      "bool": "Boolean",
      "time": "Time ⏰",
      "number": "Number 🔢",
      "datetime": "Date and time",
      "duration": "Duration ⏳",
      "cv_bool": "Config validation boolean",
      "plain_bool": "Plain boolean"
    },
    "extra_fields_descriptions": {
      "bool": "Boolean helper text",
      "time": "A nice time",
      "number": "Some number between 10 and 100",
      "datetime": "Today may be the day 📅",
      "duration": "Duration ⏳"
    }
  }
}
previous extra field translation support
Bildschirmfoto 2024-04-20 um 16 46 25 Bildschirmfoto 2024-04-20 um 16 45 25

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

) || schema.name;
) ||
localize(
`component.${trigger.domain}.device_automation.extra_fields.${schema.name}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to load these translations somewhere, or do the device automation controls already load them?

Copy link
Contributor Author

@farmio farmio Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is already loaded since the backends strings.jsons

{
  "device_automation": {
    "condition_type": {...}
    "trigger_type": {...}
  }
}

keys are already loaded too. I'm not sure where this happens though 😬.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The automation editor loads them:

this.hass.loadBackendTranslation("device_automation");

// Returns a callback for ha-form to calculate labels per schema object
return (schema) =>
return (schema): string =>
localize(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt the order be reversed? The component should be able to override the default translations I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. Do you know where these default translations are used?

"extra_fields": {
                    "above": "Above",
                    "below": "Below",
                    "for": "Duration (optional)",
                    "zone": "[%key:ui::panel::config::automation::editor::triggers::type::zone::label%]"
                  },

I would think of sensor domain, but for the "zone" key I'm not sure. Should it maybe be moved to backend (like components/sensor/strings.json)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should be moved to the backend.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved all of this to the backend and removed the translations from the frontend. home-assistant/core@c20bd32

Also moved the ComputeLabelCallback functions to a common module so it can be used by conditions and actions too.

@farmio farmio changed the title Translation support for device trigger extra fields Translation support for device automation extra fields Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants