Fix translation of file types in CWS - #1475
Merged
Merged
Conversation
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.
veluca93
approved these changes
Jul 23, 2025
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 #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 :)