KLocalizedString: Using an empty domain, fix the code

Ingo Klöcker kloecker at kde.org
Mon Dec 9 08:21:42 GMT 2024


On Montag, 9. Dezember 2024 05:23:15 Mitteleuropäische Normalzeit Jasem Mutlaq 
wrote:
> In KStars previous release, we migrated away from I18N_NOOP and used ki18n.
> With KStars 3.7.3 release, we don't see errors about using an empty domain
> and our users were able to switch languages successfully in KStars.
> 
> With our latest release, our users alerted us that switching language no
> longer works. The output is filled with these messages:
> 
> kf.i18n: KLocalizedString: Using an empty domain, fix the code. msgid:
> "unnamed" msgid_plural: "" msgctxt: ""
> kf.i18n: KLocalizedString: Using an empty domain, fix the code. msgid:
> "unnamed object" msgid_plural: "" msgctxt: ""
> kf.i18n: KLocalizedString: Using an empty domain, fix the code. msgid:
> "star" msgid_plural: "" msgctxt: ""
> kf.i18n: KLocalizedString: Using an empty domain, fix the code. msgid:
> "unnamed" msgid_plural: "" msgctxt:
> 
> The domain is set correctly in main.cpp
> 
> So what did change in KDE Frameworks that would have caused this?
> 
> The code for the above error messages is in here (among other places):
> 
> https://invent.kde.org/education/kstars/-/blob/master/kstars/skyobjects/skyo
> bject.h?ref_type=heads#L22

You are doing
```
namespace {
    const auto emptyString = QStringLiteral();
    const auto unnamedString = ki18n("unnamed").toString();
    const auto unnamedObjectString = ki18n("unnamed object").toString();
    const auto starString = ki18n("star").toString();
}
```

This doesn't work because the translation happens (and fails) long before the 
main function. You have to use kli18n("unnamed") to create a 
KLazyLocalizedString and you have to call .toString() on those objects where 
you use them.

Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-devel/attachments/20241209/2cacd4d5/attachment.sig>


More information about the kde-devel mailing list