openhab / openhab-core

Core framework of openHAB
https://www.openhab.org/
Eclipse Public License 2.0
915 stars 422 forks source link

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

Open lolodomo opened 2 years ago

lolodomo commented 2 years ago

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 ?

lolodomo commented 2 years ago

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 commented 2 years ago

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.

cweitkamp commented 2 years ago

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.

lolodomo commented 2 years ago

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 commented 2 years ago

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

lolodomo commented 2 years ago

Discovery is now OK.

Remains the creation of dynamic channel types and channels.

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

J-N-K commented 2 years ago

@lolodomo Are you still working on this?

lolodomo commented 2 years ago

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

lolodomo commented 2 years ago

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