Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-33324

Plugin installation directory available to the plugin itself

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Not Evaluated Not Evaluated
    • None
    • Qt Creator 17.0.0
    • All Other Issues
    • None

      When trying to add translations to cristianadam/llama.qtcreator: Local LLM-assisted text completion for Qt Creator. I noticed that I needed the path to my translations directory in order to tell QTranslator to load the translation.

      I ended up having something like:

      static FilePath scanForTranslation(const QString &translationFile)
      {
          const FilePaths &pluginPaths = ExtensionSystem::PluginManager::pluginPaths();
          for (const FilePath &plugin : pluginPaths) {
              const FilePaths pluginFolders = plugin.dirEntries(
                  FileFilter({}, QDir::Dirs | QDir::NoDotAndDotDot));
      
              for (const FilePath &folder : pluginFolders) {
                  FilePath translationDir = folder
                                            / (HostOsInfo::isMacHost()
                                                   ? QString("Qt Creator.app/Contents/Resources")
                                                   : QString("share/qtcreator"))
                                            / "translations";
                  if (!translationDir.dirEntries({{translationFile}, QDir::Files | QDir::NoDotAndDotDot})
                           .isEmpty())
                      return translationDir.pathAppended(translationFile);
              }
          }
          return FilePath();
      }
      

      I think it would be faster and easier if the plugin had the knowledge where it was installed.

      The alternative would be to use a qrc file to have the translations inside the plugin binary itself...

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            con Eike Ziller
            cadam Cristian Adam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes