網站首頁 編程語言 正文
前言
有些時候我們在父類中使用了 self.tr('XXX'),使用 Qt Linguist 完成翻譯并導出 qm 文件后,發現子類中仍然是英文原文。比如下面這段代碼:
class AlbumCardBase(QWidget): ? ? """ 專輯卡基類 """ ? ? def __init__(self, parent=None): ? ? ? ? super().__init__(parent=parent) ? ? ? ? self.playButton = BlurButton( ? ? ? ? ? ? self, ? ? ? ? ? ? (30, 65), ? ? ? ? ? ? ":/images/album_tab_interface/Play.png", ? ? ? ? ? ? self.coverPath, ? ? ? ? ? ? self.tr('Play') ? ? ? ? ) ? ? ? ? self.addToButton = BlurButton( ? ? ? ? ? ? self, ? ? ? ? ? ? (100, 65), ? ? ? ? ? ? ":/images/album_tab_interface/Add.png", ? ? ? ? ? ? self.coverPath, ? ? ? ? ? ? self.tr('Add to') ? ? ? ? )
父類 AlbumCardBase 中有兩處使用了 tr 函數,分別翻譯為 播放 和 添加到,但是在子類中這些文本仍然會顯示為 Play 和 Add to,下面來看看如何解決這個問題。
解決過程
生成的 ts 文件中,有這樣一段代碼:
<context> ? ? <name>AlbumCardBase</name> ? ? <message> ? ? ? ? <location filename="../../components/album_card/album_card_base.py" line="50"/> ? ? ? ? <source>Add to</source> ? ? ? ? <translation>添加到</translation> ? ? </message> ? ? <message> ? ? ? ? <location filename="../../components/album_card/album_card_base.py" line="43"/> ? ? ? ? <source>Play</source> ? ? ? ? <translation>播放</translation> ? ? </message> </context>
可以看到上述代碼描述了源文的位置和內容以及譯文,但是只對父類 AlbumCardBase 起作用。要想對子類應用上述規則,只需粘貼再修改 <name> 標簽中的類名即可,比如 AlbumCard 為子類,那么只需添加下述代碼:
<context> ? ? <name>AlbumCard</name> ? ? <message> ? ? ? ? <location filename="../../components/album_card/album_card_base.py" line="50"/> ? ? ? ? <source>Add to</source> ? ? ? ? <translation>添加到</translation> ? ? </message> ? ? <message> ? ? ? ? <location filename="../../components/album_card/album_card_base.py" line="43"/> ? ? ? ? <source>Play</source> ? ? ? ? <translation>播放</translation> ? ? </message> </context>
完成上述步驟后導出 qm 文件即可。
原文鏈接:https://www.cnblogs.com/zhiyiYo/p/15862675.html
相關推薦
- 2023-02-01 python?multiply()與dot使用示例講解_python
- 2022-04-20 Django學習之靜態文件與模板詳解_python
- 2022-04-20 基于PyQT5制作一個桌面摸魚工具_python
- 2023-04-24 如何修改Linux內核參數vm.swappiness_Linux
- 2022-04-15 ASP.NET?Core基礎之中間件_基礎應用
- 2022-07-04 C語言植物大戰數據結構堆排序圖文示例_C 語言
- 2022-11-01 Android串口通訊SerialPort的使用詳情_Android
- 2022-10-24 Golang設計模式工廠模式實戰寫法示例詳解_Golang
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支