chore: don't use hardcode path#168
chore: don't use hardcode path#168deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom wineee:path
Conversation
Log: don't use hardcode path
| { | ||
| NetworkController::setIPConflictCheck(true); | ||
| QTranslator *translator = new QTranslator(this); | ||
| translator->load(QString("/usr/share/dock-network-plugin/translations/dock-network-plugin_%1.qm").arg(QLocale::system().name())); |
There was a problem hiding this comment.
可以使用DGuiApplicationHelper::loadTranslator接口
There was a problem hiding this comment.
不行,这个是插件,这意味这 dtk 会在 dde-dock 的路径寻找(因为 ApplicationName 是 dde-dock),而不是 dock-network-plugin
一种方法是调用 loadTranslator 前 setApplicationName(dock-network-plugin), 调用后再改回来,deepin-screen-recorder 的 dock 插件是这样做的,但是我认为为了翻译修改 ApplicationName 不是规范行为
There was a problem hiding this comment.
loadTranslator也是需要自己传目录的,appdir只是它内部的一个fallback而已,类似这样的
QList<QString> translateDirs;
const QString dtkdeclarativeTranslationPath(DDECLARATIVE_TRANSLATIONS_DIR);
auto dataDirs = DStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
for (const auto &path : dataDirs) {
DPathBuf DPathBuf(path);
translateDirs << (DPathBuf / dtkdeclarativeTranslationPath).toString();
}
DGuiApplicationHelper::loadTranslator("dtkdeclarative", translateDirs, QList<QLocale>() << QLocale::system());
There was a problem hiding this comment.
这种写法似乎比我现在的改法还要长,而且都是从 StandardPaths::GenericDataLocation 中找,有什么优势吗
There was a problem hiding this comment.
都是拼接路径去找翻译文件,只是loadTranslator 这里面处理了一些翻译文件的路径问题,加了点儿fallback来应对其他特殊的语言系统,
QStandardPaths::locateAll()来当作目录的话会简单点儿,
There was a problem hiding this comment.
当然,这种东西可改可不改,只是dtkgui里有这个接口去加载翻译文件,可以去使用它而已,
There was a problem hiding this comment.
不对,有点问题,现在 dde-control-center 负责加载插件翻译了,这里是应该直接删掉吧
upd: 看错了,dde-control-center 的已经删了,
There was a problem hiding this comment.
那就先这样改吧, dss 和 dock 应该也要像 dde-control-center 那样自己负责插件翻译的,这部分不久后就该删了
|
/merge |
Log: don't use hardcode path
恢复 chore: don't use hardcode path #56
使用 GNUInstallDirs 安装路径
使用 QStandardPaths (从 XDG_DATA_DIRS or /usr/share)搜索翻译
dde-session-shell/modules 从 /lib 改到 /usr/lib