Skip to content

Use AppStream metadata for localized package descriptions - #64

Open
wehrwolfmann wants to merge 1 commit into
CachyOS:developfrom
wehrwolfmann:appstream-descriptions
Open

Use AppStream metadata for localized package descriptions#64
wehrwolfmann wants to merge 1 commit into
CachyOS:developfrom
wehrwolfmann:appstream-descriptions

Conversation

@wehrwolfmann

Copy link
Copy Markdown

Fixes #62.

Descriptions currently come from the pacman database (pkgdesc), which has no notion of translation: one string per package, one language. This reads the summary from the system AppStream catalogue instead and falls back to pkgdesc whenever AppStream has nothing to offer.

What it does

find_package(AppStreamQt 1.0 QUIET)optional. Without it the code is compiled out and behaviour is exactly as today. The dependency is appstream-qt, in extra and in the CachyOS repos; the catalogue data comes from archlinux-appstream-data, which is already pulled in by Discover on most desktops.

The catalogue is loaded once at start-up into a pkgname → summary map, measured at about 75 ms with a warm cache.

Verification

Built twice on a clean checkout of develop (0c33b27), with and without the patch: both succeed, and the patched build produces no new warnings (the one -Wshadow in mainwindow.cpp is pre-existing). CMake prints AppStreamQt found: descriptions will be localized.

Run under LANG=ru_RU.UTF-8, Elisa now shows its Russian summary instead of the English pkgdesc. A side effect worth mentioning: search starts working in the user's language — before the patch, typing a Russian word matched nothing, because every description was English.

The three fallback paths were exercised, not assumed:

case result
no AppStream catalogue on the system summaries loaded: 0, falls back to pkgdesc
package absent from the catalogue (vim) falls back to pkgdesc
component present but summary empty falls back to pkgdesc

The third one does not occur in the real catalogue, so I built a synthetic one to exercise the branch.

One behaviour worth knowing

If a component exists but has no translation for the user's locale, libappstream returns the English AppStream summary, which is not always the same text as pkgdesc — for example mixxx reads "Everything you need to perform live DJ mixes" instead of "Free, open source software for digital DJing". Nothing goes blank, and Discover and pamac behave the same way, but the English string can change.

Happy to adjust the approach if you would rather load the catalogue lazily or key it differently.

Descriptions currently come from the pacman database (pkgdesc via
alpm_manager), which holds one English string per package and has no
translations. As a result the description column stays English even when
the user's language is fully supported by the application being listed.

The distribution already ships translated summaries: archlinux-appstream-data
installs /usr/share/swcatalog/xml/{core,extra,multilib}.xml.gz, where each
component carries <pkgname> plus <summary xml:lang=".."> for every language
it has been translated into. libappstream picks the right language from the
current locale on its own. This is where Discover and pamac get their
descriptions from.

Build a package name -> summary map once at start-up and prefer it over
pkgdesc in both the popular apps tree and the repository tree. When AppStream
is missing, the summary is empty, or the package has no component at all
(CLI tools mostly), the pkgdesc is used exactly as before.

Only the OS catalogue is loaded, since it is the only source that carries
package names; on a Plasma install that is 1572 components and one pass
over them costs about 75 ms, measured. Looking components up one by one via
componentsByBundleId() was measured slower for this workload (256 ms for the
147 packages of pkglist.yaml), because each lookup is a separate query.

AppStreamQt is an optional dependency: without it the code compiles out and
behaviour is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Descriptions are always English even when a translation is available on the system

1 participant