Skip to content

Fix translation of file types in CWS - #1475

Merged
prandla merged 2 commits into
cms-dev:mainfrom
e-i-o:fix-mimetypes
Jul 23, 2025
Merged

Fix translation of file types in CWS#1475
prandla merged 2 commits into
cms-dev:mainfrom
e-i-o:fix-mimetypes

Conversation

@prandla

@prandla prandla commented Jul 22, 2025

Copy link
Copy Markdown
Member

Fixes #850.

Previously, we tried to find shared-mime-info.mo and use that to translate the descriptions obtained from xdg.Mime into the right language. This was not the correct approach: first, the path to shared-mime-info.mo varied (on Ubuntu it was in locale-langpack instead of locale), and second, sometimes (e.g. on Fedora) it was not present at all.

The right place to find these translations is in the mimetype xml files themselves. However, this caused other issues: first, pyxdg does not have proper support for using more than one language. I hacked around this by setting the (global) language before each call, and clearing pyxdg's own cache. And then adding my own cache on top that can cache multiple languages. The second problem was that on Debian/Ubuntu, the xml:lang tags that specify the language codes for each string use an incorrect format: they use POSIX-style locale names (like zh_CN) instead of XML-compliant BCP47 language codes (like zh-Hans-CN). pyxdg only knows how to handle these incorrect names, so I had to implement a hack to get it to recognize the correct names too.

Also deleted the undocumented and now-unused shared_mime_info_prefix config option, and mentioned shared-mime-info as a dependency in the installation docs.

Bonus trivia: #850 asks how to find the correct path to shared-mime-info.mo. The answer is: /usr/share/locale, except on specifically Ubuntu, where it's either /usr/share/locale or /usr/share/locale-langpack :)

Previously, we tried to find shared-mime-info.mo and use that to
translate the descriptions obtained from xdg.Mime into the right
language. This was not the correct approach: first, the path to
shared-mime-info.mo varied (on Ubuntu it was in locale-langpack instead
of locale), and second, sometimes (e.g. on Fedora) it was not present at
all.

The right place to find these translations is in the mimetype xml
files themselves. However, this caused other issues: first, pyxdg does
not have proper support for using more than one language. I hacked
around this by setting the (global) language before each call, and
clearing pyxdg's own cache. And then adding my own cache on top that can
cache multiple languages. The second problem was that on Debian/Ubuntu,
the xml:lang tags that specify the language codes for each string use an
incorrect format: they use POSIX-style locale names (like zh_CN) instead
of XML-compliant BCP47 language codes (like zh-Hans-CN). pyxdg only
knows how to handle these incorrect names, so I had to implement a hack
to get it to recognize the correct names too.

Also deleted the undocumented and now-unused shared_mime_info_prefix
config option, and mentioned shared-mime-info as a dependency in the
installation docs.
@prandla
prandla merged commit 4e485d8 into cms-dev:main Jul 23, 2025
2 of 3 checks passed
@prandla
prandla deleted the fix-mimetypes branch July 23, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Translating the descriptions of attachments' types has never worked

2 participants