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

[mielecloud] Fix i18n in addon.xml #14310

Merged
merged 1 commit into from
Feb 1, 2023
Merged

Conversation

mhilbush
Copy link
Contributor

@mhilbush mhilbush commented Feb 1, 2023

Fix i18n tags in addon.xml so binding name and description displays correctly in binding list.

Signed-off-by: Mark Hilbush [email protected]

Signed-off-by: Mark Hilbush <[email protected]>
@mhilbush mhilbush added the bug An unexpected problem or unintended behavior of an add-on label Feb 1, 2023
@mhilbush mhilbush requested a review from BjoernLange as a code owner February 1, 2023 14:46
@mhilbush
Copy link
Contributor Author

mhilbush commented Feb 1, 2023

BTW, this problem may exist in other bindings. If this is the correct fix, I can submit a another PR for the others.

./bundles/org.openhab.binding.sagercaster/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/bindingName</name>
./bundles/org.openhab.binding.sagercaster/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/bindingDescription</description>
./bundles/org.openhab.binding.nanoleaf/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/binding.nanoleaf.name</name>
./bundles/org.openhab.binding.nanoleaf/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/binding.nanoleaf.description</description>
./bundles/org.openhab.binding.digitalstrom/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/binding_name</name>
./bundles/org.openhab.binding.digitalstrom/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/binding_desc</description>
./bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/bindingName</name>
./bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/bindingDescription</description>
./bundles/org.openhab.binding.jeelink/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/binding.jeelink.name</name>
./bundles/org.openhab.binding.jeelink/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/binding.jeelink.description</description>
./bundles/org.openhab.binding.velux/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/binding.velux.name</name>
./bundles/org.openhab.binding.velux/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/binding.velux.description</description>
./bundles/org.openhab.binding.amazondashbutton/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/bindingName</name>
./bundles/org.openhab.binding.amazondashbutton/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/bindingDescription</description>
./bundles/org.openhab.binding.pushbullet/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/binding.pushbullet.name</name>
./bundles/org.openhab.binding.pushbullet/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/binding.pushbullet.description</description>
./bundles/org.openhab.binding.urtsi/src/main/resources/OH-INF/addon/addon.xml:7:	<name>@text/bindingLabel</name>
./bundles/org.openhab.binding.urtsi/src/main/resources/OH-INF/addon/addon.xml:8:	<description>@text/bindingDescription</description>```

Copy link
Contributor

@jlaur jlaur left a comment

Choose a reason for hiding this comment

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

Thanks! This is correct, nice catch. It would be much appreciated if you want to fix the other bindings as well.

@jlaur jlaur merged commit 96bffaa into openhab:main Feb 1, 2023
@jlaur jlaur added the regression Regression that happened during the development of a release. Not shown on final release notes. label Feb 1, 2023
@mhilbush
Copy link
Contributor Author

mhilbush commented Feb 1, 2023

It would be much appreciated if you want to fix the other bindings as well.

Certainly. I'll submit a PR for the rest of them.

@jlaur jlaur added this to the 4.0 milestone Feb 1, 2023
@mhilbush mhilbush deleted the mielecloud-fix-i18n branch February 1, 2023 17:53
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Feb 28, 2023
renescherer pushed a commit to renescherer/openhab-addons that referenced this pull request Mar 23, 2023
FordPrfkt pushed a commit to FordPrfkt/openhab-addons that referenced this pull request Apr 20, 2023
@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

@mhilbush @jlaur could you please help me understand / point me to what addon.xml is used for / by, specifically the actual string that we entered inside addon.xml <name> and <description> tags.

<name>@text/addon.mielecloud.name</name>

I understand that there's i18n/mielecloud.properties which contains addon.mielecloud.name=Miele@home Cloud Binding

My current understanding is that as long as mielecloud.properties file contains the actual text that you want (as above), it doesn't matter if you entered any gibberish inside addon.xml.

The only time it matters what is entered inside addon.xml is the fact that the content of addon.xml is collected for all the addons, and combined into /runtime/etc/addons.xml which is used by AddonInfoAddonsXmlProvider

Oh, and also when you run the i18n tools, it would read what's in the addon.xml to generate the .properties file.

@merwege I understand you encountered problems with this in openhab/openhab-core#3908
However, there's this openhab/openhab-core#3865 (AddonInfoAddonsXmlProvider that I linked above).

So:

  • We need to clean up addon.xml bindings, so that the <name> and <description> containing @text/xxxxx which AFAIK is useless (i.e. not actually used for what we might think it was intended for), are replaced with the actual text back from the i18n properties (English).
  • Modify core to start picking up the info, especially description

All this is so we can have addons description even for uninstalled addons in the UI -> So that we can search in their description, see openhab/openhab-webui#3028

Once again, I still don't understand all this, so I'd appreciate any pointers and corrections.

@mherwege
Copy link
Contributor

Thanks! This is correct, nice catch. It would be much appreciated if you want to fix the other bindings as well.

@jlaur @mhilbush I don't think you can make this assumption by just looking at the addon.xml file. The key there just needs to match the key in the properties file. You have the nikohomecontrol binding listed there as a problem, but it is correct in that case.

@mherwege
Copy link
Contributor

  • We need to clean up addon.xml bindings, so that the <name> and <description> containing @text/xxxxx which AFAIK is useless (i.e. not actually used for what we might think it was intended for), are replaced with the actual text back from the i18n properties (English).
  • Modify core to start picking up the info, especially description

@jimtng openhab/openhab-core#3908 fixes an issue that was discovered after openhab/openhab-core#3865.

The fundamental problem is that i8n info for binding is only available after loading the binding jar or kar, as it is part of the jar. Just reading the addon.xml file will never give that information. But there is another source for binding name and description from the bundle list. So instead of trying to read it from the addon.xml, it just uses it from the bundle list. This will of course never be translated. That mechanism then also copes with any string reference you use in the addon.xml file.
If you would want to be able to translate in the addon suggestion phase, you would need to build a mechanism that extracts all these binding name and binding string translations, stores them separately and makes them available as an extra service. All of this extraction would need to happen in the build phase. I am not sure that's worth it.

So I don't think there is much to do here, except making sure the string keys are the same in the addon.xml and properties files. But the impact is only when the binding is already installed, not in the addon discovery phase.

@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

@mherwege, thanks for the extra info.

bundle list

What is this? I'm guessing this is the Karaf addons info which gets its data from the feature list. If this is the case, it does not have description, only label/name (which is called "description" but it's the same as "name" in addon.xml) - I know you already knew this... I'm just restating it here for my own clarity.

That mechanism then also copes with any string reference you use in the addon.xml file.

Could you elaborate this for me please

If you would want to be able to translate in the addon suggestion phase, you would need to build a mechanism that extracts all these binding name and binding string translations, stores them separately and makes them available as an extra service. All of this extraction would need to happen in the build phase.

Yes, I figured this out too, and I am contemplating this, or some (limited) variations of it.

With all this, could you please confirm whether this is correct (inside addon.xml), and who would actually perform the translation for it:

	<name>@text/addon.mielecloud.name</name>
	<description>@text/addon.mielecloud.description</description>

From my tests, it really doesn't matter if I entered any rubbish in it, e.g.

	<name>asdfasdf</name>
	<description>asdfasdf</description>

Once the binding is built into a jar, everything I know of would report the name/description from what's inside the .properties file, and not the gibberish I entered in addons.xml

@mherwege
Copy link
Contributor

What is this? I'm guessing this is the Karaf addons info which gets its data from the feature list. If this is the case, it does not have description, only label/name (which is called "description" but it's the same as "name" in addon.xml) - I know you already knew this... I'm just restating it here for my own clarity.

Yes, indeed, the feature list. And you are right. That does not include the addon descriptions.

Could you elaborate this for me please

I am not an expert on i8n, but my understanding is this uses a standard Java mechanism. In OH we have the TranslationProvider service that makes this available. The implementation of it is here I believe: https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/i18n/I18nProviderImpl.java

Once the binding is built into a jar, everything I know of would report the name/description from what's inside the .properties file, and not the gibberish I entered in addons.xml

Even after installing the binding? I am surprised by that. I would expect the code to use the TranslationProvider to pick up the translation from the key in addon.xml to the properties file.
Did you try changing the language of your environment?
Here is where this should get resolved from the addon bundle: https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/internal/AddonI18nUtil.java
And indeed, when it doesn't find @text in the value, it probably just uses addon.addonID.name as the key (see https://github.com/openhab/openhab-core/blob/ce374252fa2c821103da888302f930c1c127f73c/bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/internal/AddonI18nUtil.java#L51).

@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

Thanks for the pointers!

Even after installing the binding?

Yes, I believe so. I checked this by writing code (in jruby) that queries org.openhab.core.addon.AddonService and org.openhab.core.addon.AddonInfoRegistry OSGi services.

Did you try changing the language of your environment?

I don't think that's necessary? My code requests specific locales in the call to getAddons(locale) and getAddonInfo(id, locale), and I can confirm I am seeing the different languages being returned in the description.

And indeed, when it doesn't find @text in the value, it probably just uses addon.addonID.name as the key (see https://github.com/openhab/openhab-core/blob/ce374252fa2c821103da888302f930c1c127f73c/bundles/org.openhab.core.addon/src/main/java/org/openhab/core/addon/internal/AddonI18nUtil.java#L51).

Thank you! That really says that if you entered anything but @text/, it will be ignored and the text will then be inferred from the addon.addonID.name. So the only time you'd need to use @text/ is when you need to use a non-standard id.

So given this fact, why don't we just populate all addon.xml with the actual text, which we can then use in AddonInfoAddonsXmlProvider for the purpose of providing descriptions to webui? Even if we just have English, it is still going to be a big improvement to allow people to search inside the description.

Of course, in the conversion process of addon.xml, we'll need to ensure any replacements will still result in the same text for translation purposes.

WDYT?

@jlaur
Copy link
Contributor

jlaur commented Jan 20, 2025

So given this fact, why don't we just populate all addon.xml with the actual text

IMHO that would be great. For completeness, I'll just add that in theory you have no redundancy when having:

<name>@text/addon.mielecloud.name</name>
<description>@text/addon.mielecloud.description</description>

pointing towards:

addon.mielecloud.name=Miele@home Cloud Binding
addon.mielecloud.description=This is the cloud-based Miele@home binding.

With:

	<name>Miele@home Cloud Binding</name>
	<description>This is the cloud-based Miele@home binding.</description>

you have the same strings in two places.

OTOH, with the i18n:generate-default-translations approach we can consider the properties file as (partially) auto-generated rather than manually created, so the redundancy shouldn't matter as long as we remember to run the tool after changing texts. This also dramatically reduces the risk of human mistakes of providing invalid @text/key references.

@mherwege
Copy link
Contributor

mherwege commented Jan 20, 2025

So this would mean:

  1. For all addons, in the addon.xml file, replace the name and description field content with the actual strings, without @text/ at the start.
  2. Generate the default translations (and remove the old keys from the property files).

From reading through the code, I believe the name and description should then be available in English when the addon is not installed, and in local language when it gets installed.

We might want a script to run to make these changes to all addons in the repository in one go.

@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

We might want a script to run to make these changes to all addons in the repository in one go.

There aren't that many. I can do it manually. It's just a one-off operation.

@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

OTOH, with the i18n:generate-default-translations approach we can consider the properties file as (partially) auto-generated rather than manually created, so the redundancy shouldn't matter as long as we remember to run the tool after changing texts. This also dramatically reduces the risk of human mistakes of providing invalid @text/key references.

Indeed. This is why I was confused when I discovered this @text/key inside addon.xml. But the i18n:generate-default-translations is smart enough not to touch the @text/ stuff.

A case when this @text/ may be handy is to remove duplications (e.g. multiple configuration parameters with the same description perhaps?) but that doesn't apply here for name/description.

@mherwege
Copy link
Contributor

A case when this @text/ may be handy is to remove duplications (e.g. multiple configuration parameters with the same description perhaps?) but that doesn't apply here for name/description.

And it is also handy when you need string replacements inside the string to be translated. But again, this does not apply for the binding name and description.

There aren't that many. I can do it manually. It's just a one-off operation.

When you do that, can you also try to check if there are already translations to keep these? Or would they have to be redone in Crowdin anyway to stay in sync?

@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

There aren't that many. I can do it manually. It's just a one-off operation.

When you do that, can you also try to check if there are already translations to keep these? Or would they have to be redone in Crowdin anyway to stay in sync?

Already started doing this. Found only 11 bindings.

I was told not to touch the other languages, so I'll only change the main .properties (if needed)

@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

Found more bugs in core while doing this, but it's not immediately related... so I'll deal with this later:

  • built a bundle, e.g. icloud with custom name/description (e.g. XXXiCloud Binding). Then dropped that jar in my addons/ folder, then this happens:
image

The "official" binding shouldn't be copying the jar binding's name/description. But this is probably debatable, since they both share the same addon uid, just from different addonprovider

There are also other issues, not directly related to the topic at hand... for another time to deal with.

Just making a note here to remind myself

@mherwege
Copy link
Contributor

The "official" binding shouldn't be copying the jar binding's name/description. But this is probably debatable, since they both share the same addon uid, just from different addonprovider

The addon info merge treats what is coming from addon.xml as non-master and something coming from a bundle as master. This is to make sure the translations are applied. If it comes from addon.xml, it cannot be applied. If it comes from a jar, translations could be there. So as this is the same addon id, I think this is acceptable here.

@mherwege
Copy link
Contributor

There are also other issues, not directly related to the topic at hand... for another time to deal with.

What are these issues? Maybe create an issue for them.

@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

There are also other issues, not directly related to the topic at hand... for another time to deal with.

What are these issues? Maybe create an issue for them.

I noticed that the JarFileAddonService doesn't utilise localization. I haven't fully delved into it though as I didn't want to go on a tangent every time I found something odd (at least to me).

@jimtng
Copy link
Contributor

jimtng commented Jan 20, 2025

The "official" binding shouldn't be copying the jar binding's name/description. But this is probably debatable, since they both share the same addon uid, just from different addonprovider

The addon info merge treats what is coming from addon.xml as non-master and something coming from a bundle as master. This is to make sure the translations are applied. If it comes from addon.xml, it cannot be applied. If it comes from a jar, translations could be there. So as this is the same addon id, I think this is acceptable here.

I guess the issue here is that the karaf / official addons should not be mixed up with jar addons. But it's not a big issue, so I'm happy to let it be for now.

Theoretically someone can build a bunch of bogus jar addons that would override official bindings' name / descriptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on regression Regression that happened during the development of a release. Not shown on final release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants