Skip to content

chore: don't use hardcode path#168

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wineee:path
May 6, 2023
Merged

chore: don't use hardcode path#168
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
wineee:path

Conversation

@wineee
Copy link
Member

@wineee wineee commented May 5, 2023

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

@wineee wineee requested a review from ComixHe May 5, 2023 06:49
Log: don't use hardcode path
@wineee wineee requested a review from Decodetalkers May 5, 2023 07:08
@Decodetalkers Decodetalkers requested a review from 18202781743 May 5, 2023 07:17
{
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()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以使用DGuiApplicationHelper::loadTranslator接口

Copy link
Member Author

@wineee wineee May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不行,这个是插件,这意味这 dtk 会在 dde-dock 的路径寻找(因为 ApplicationName 是 dde-dock),而不是 dock-network-plugin

一种方法是调用 loadTranslator 前 setApplicationName(dock-network-plugin), 调用后再改回来,deepin-screen-recorder 的 dock 插件是这样做的,但是我认为为了翻译修改 ApplicationName 不是规范行为

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种写法似乎比我现在的改法还要长,而且都是从 StandardPaths::GenericDataLocation 中找,有什么优势吗

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

都是拼接路径去找翻译文件,只是loadTranslator 这里面处理了一些翻译文件的路径问题,加了点儿fallback来应对其他特殊的语言系统,
QStandardPaths::locateAll()来当作目录的话会简单点儿,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当然,这种东西可改可不改,只是dtkgui里有这个接口去加载翻译文件,可以去使用它而已,

Copy link
Member Author

@wineee wineee May 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不对,有点问题,现在 dde-control-center 负责加载插件翻译了,这里是应该直接删掉吧

upd: 看错了,dde-control-center 的已经删了,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那就先这样改吧, dss 和 dock 应该也要像 dde-control-center 那样自己负责插件翻译的,这部分不久后就该删了

@wineee wineee marked this pull request as draft May 6, 2023 05:25
@wineee wineee marked this pull request as ready for review May 6, 2023 05:34
@wineee
Copy link
Member Author

wineee commented May 6, 2023

/merge

@deepin-bot deepin-bot bot merged commit 17e838f into linuxdeepin:master May 6, 2023
@wineee wineee deleted the path branch May 6, 2023 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants