Use AppStream metadata for localized package descriptions - #64
Open
wehrwolfmann wants to merge 1 commit into
Open
Use AppStream metadata for localized package descriptions#64wehrwolfmann wants to merge 1 commit into
wehrwolfmann wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 topkgdescwhenever 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 isappstream-qt, inextraand in the CachyOS repos; the catalogue data comes fromarchlinux-appstream-data, which is already pulled in by Discover on most desktops.The catalogue is loaded once at start-up into a
pkgname → summarymap, 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-Wshadowinmainwindow.cppis pre-existing). CMake printsAppStreamQt found: descriptions will be localized.Run under
LANG=ru_RU.UTF-8, Elisa now shows its Russian summary instead of the Englishpkgdesc. 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:
summaries loaded: 0, falls back topkgdescvim)pkgdescpkgdescThe 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 examplemixxxreads "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.