openhab-core icon indicating copy to clipboard operation
openhab-core copied to clipboard

Label/description handling @text strings when building a channel type, a channel or a discovery result

Open lolodomo opened this issue 4 years ago • 9 comments

When building a channel type, a channel or a discovery result, it would be interesting to be able to pass a @text string referencing a property file for the label and for the description. This will help binding internationalization.

@cweitkamp : as you are our specialist for i18n, do you thing this is doable and easy ?

  • [x] Discovery result
  • [x] Channel type
  • [ ] Channel

lolodomo avatar Oct 28 '21 21:10 lolodomo

For discovery results, we already have a search in property files so maybe it is just a bug if @text is not supported. Unfortunately I don't find immediately the class implementing the current behavior.

lolodomo avatar Oct 29 '21 06:10 lolodomo

Found for discovery https://github.com/openhab/openhab-core/blob/79edf2b9e643ad802c31b2e5f54edb93534277fd/bundles/org.openhab.core.config.discovery/src/main/java/org/openhab/core/config/discovery/AbstractDiscoveryService.java#L252

So it should work in theory with @text.

Edit: the problem is when a binding uses DiscoveryResultBuilder.create rather than ThingDiscovered which is the case for mDNS or UPNP discovery for example. Edit2; the core framework is then calling ThingDiscovered in such a case, so it should work.

lolodomo avatar Oct 29 '21 07:10 lolodomo

IIRC discovery already supports translations. And I bet it was implemented by yourself back in the days (see https://github.com/eclipse-archived/smarthome/pull/4177).

I am not sure about channel types. If a binding provides custom channel types there must be a registry implementation too. If so it should be responsible for correct localization. Same for channel group types.

Currently I do not have an idea how to handle channels. At best they should always use an already available channel type and inherit label/description/options and so on from it. I am aware that everything can be overwritten. Same for channel groups.

cweitkamp avatar Oct 29 '21 10:10 cweitkamp

For discovery, using @text is not working, I will have to investigate a little more why and in what case exactly it fails. If I use "@text/toto" as label, I see"@text/toto" In MainUI. It behaves as if the property is not found.

lolodomo avatar Oct 29 '21 11:10 lolodomo

It probably fails because MDNSDiscoveryService is a core service so properties are not searched in the binding bundle but in one core bundle.

lolodomo avatar Oct 29 '21 12:10 lolodomo

Discovery is now OK.

Remains the creation of dynamic channel types and channels.

For channel type, I have the feeling I could use ChannelTypeI18nLocalizationService.

lolodomo avatar Nov 17 '21 18:11 lolodomo

@lolodomo Are you still working on this?

J-N-K avatar May 21 '22 18:05 J-N-K

This is on my TODO list, but not very high to be honest.

lolodomo avatar May 21 '22 19:05 lolodomo

For channel types, I can confirm that ChannelTypeI18nLocalizationService .createLocalizedChannelType is the solution to localize channel types built dynamically.

lolodomo avatar Jun 25 '22 08:06 lolodomo