Results 1 to 11 of 11

Thread: Plugin and internationalization

  1. #1
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Plugin and internationalization

    Hi!
    I build my plugins, but can't load compiled language files.
    Plugins automatically don't load language files that's lie near. (Becase it do QCore... class)
    When I try to put phrases into main application langugage file, nothing happense too.
    I Know that we can use Language loading by hand, but don't know how set this language file for plugin. (only for Application)
    Succes is 5% of talent and 95% of work!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin and internationalization

    You have to load the files manualy into the translators while initialising plugins.

  3. #3
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin and internationalization

    You mean I need load translations in main application?
    And then tell to plugin thats we load it ?
    Maybe a little sample of code ?
    Succes is 5% of talent and 95% of work!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin and internationalization

    Hmm... Your plugin class should contain a method to create a translator ready to install, something like:

    Qt Code:
    1. struct MyPluginInterface {
    2. virtual ~MyPluginInterface(){};
    3. virtual QTranslator *pluginTranslator(QString locale) = 0;
    4. // ...
    5.  
    6. };
    To copy to clipboard, switch view to plain text mode 

    Your plugin should implement it like so:

    Qt Code:
    1. QTranslator *MyPluginImplementation::pluginTranslator(QString locale){
    2. QTranslator *translator = new QTranslator(this);
    3. // you may need to change "this" to something else above
    4. translator->load(":/translations/"+locale+".qm");
    5. return translator;
    6. }
    To copy to clipboard, switch view to plain text mode 

    And your main app:

    Qt Code:
    1. QObject *plugin = loader.instance();
    2. if(plugin){
    3. MyPluginInterface *piface = qobject_cast<MyPluginInterface*>(plugin);
    4. qApp->installTranslator(piface->translator("pl_PL");
    5. }
    To copy to clipboard, switch view to plain text mode 

    You can try to load the translator directly from the plugin too instead of doing it in the main app.

  5. #5
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin and internationalization

    You mean that's "tr" function used in plugin will be traslated by "qm" loaded from main application...
    Yes, plugin can't define his translator by default, but we can inherit QTCore....
    Today i try your way.
    Succes is 5% of talent and 95% of work!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin and internationalization

    Quote Originally Posted by blackliteon
    You mean that's "tr" function used in plugin will be traslated by "qm" loaded from main application...
    Yes, sure.
    Yes, plugin can't define his translator by default, but we can inherit QTCore....
    I don't understand what you mean here. Definitely not "inherit". You can have only one QCoreApplication object in an application. But there is a global pointer to a QApplication object available, so you can use it anywhere.

  7. #7
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin and internationalization

    If I understand you when we use tr everywhere we use QCoreApplication ?
    Succes is 5% of talent and 95% of work!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin and internationalization

    tr() is just a call which uses an installed translator to get a translation for a string. Translators are installed in the application object, so yes, if you use tr() a call to the application object is made behind the scene.

  9. #9
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin and internationalization

    So we use installTranslator function for each translator.
    You mean that's translator add language phrases
    I mean that if we load for every plugin his translational file all of them will be summed (phrases) ?
    Succes is 5% of talent and 95% of work!

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Plugin and internationalization

    Quote Originally Posted by blackliteon
    I mean that if we load for every plugin his translational file all of them will be summed (phrases) ?
    Yes, they will.

  11. #11
    Join Date
    Jan 2006
    Location
    Saint-Petersburg (Russia)
    Posts
    41
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin and internationalization

    Thanks! Theme closed!
    Succes is 5% of talent and 95% of work!

Similar Threads

  1. Trouble with plugin system's documentation
    By niklas in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2009, 22:07
  2. Plugin implementation question
    By JPNaude in forum Qt Programming
    Replies: 12
    Last Post: 27th August 2008, 20:24
  3. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13
  4. plugin loading problem
    By naresh in forum Qt Programming
    Replies: 6
    Last Post: 9th June 2007, 19:05
  5. Qt4 win opensource + mysql plugin
    By vr in forum Installation and Deployment
    Replies: 3
    Last Post: 25th May 2007, 09:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.