Results 1 to 11 of 11

Thread: Fall back to untranslated mode

  1. #1
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Fall back to untranslated mode

    My application is able to perform run-time translation but I'm facing a weird issue : after switching between various available languages I want to have english (default language) again. I thus created proper files using prefix _untranslated instead of, for instance, _fr or _de. These are empty .qm files. I load remove old translators load new files and install them but the texts everywhere in the app remain in the previous language... as if translators were remanent and continued to work even after having been removed (and deleted...). I'm just wondering if it's a Qt bug. Will I be forced to create an english translation (of english texts... )?
    Current Qt projects : QCodeEdit, RotiDeCode

  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: Fall back to untranslated mode

    Quote Originally Posted by fullmetalcoder View Post
    I'm just wondering if it's a Qt bug.
    No, I don't think so.
    Will I be forced to create an english translation (of english texts... )?
    It's advised to have an english catalog file so I'm wondering why you haven't done that yet. The texts inside can be untranslated, but the files can't be empty.

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Fall back to untranslated mode

    Quote Originally Posted by wysota View Post
    It's advised to have an english catalog file so I'm wondering why you haven't done that yet. The texts inside can be untranslated, but the files can't be empty.
    My understanding was that, without any translator loaded, the text wouldn't be translated and will rename as they are inside the code (thus in english in my case). That's why I didn't filled an english ts file (isn't it tedious to fill about 300 translations by hand when you don't have anything to translate actually...).
    Current Qt projects : QCodeEdit, RotiDeCode

  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: Fall back to untranslated mode

    Quote Originally Posted by fullmetalcoder View Post
    My understanding was that, without any translator loaded, the text wouldn't be translated and will rename as they are inside the code (thus in english in my case).
    Yes, but you have to apply the new translator, otherwise strings already translated won't be "untranslated".

    That's why I didn't filled an english ts file (isn't it tedious to fill about 300 translations by hand when you don't have anything to translate actually...).
    As I mentioned you don't have to "translate" those messages, it's only important that you apply a valid qm file containing message ids.

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Fall back to untranslated mode

    Quote Originally Posted by wysota View Post
    As I mentioned you don't have to "translate" those messages, it's only important that you apply a valid qm file containing message ids.
    But that's exactly what I'm doing... Maybe the fact that I "lrealease" a .ts file which holds only "unfinished" translations make it empty and prevents the "untranslation"... If so how do I get a valid qm file from an ts file with only empty translations?
    Current Qt projects : QCodeEdit, RotiDeCode

  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: Fall back to untranslated mode

    But do you install the translator? Could you show your code? Which Qt version do you use? I used english translations files successfully without problems...

    BTW. You can try loading the .ts file instead of .qm. And what does installTranslator report?

    Edit: Sorry, I meant QTranslator::load. installTranslator returns void.

  7. #7
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Fall back to untranslated mode

    Quote Originally Posted by wysota View Post
    But do you install the translator? Could you show your code? Which Qt version do you use?
    I'm using the prebuilt Qt 4.3.0 package that comes with Frugalware.
    Here comes the code :

    Qt Code:
    1. void EdyukTranslator::setLanguage(const QString& lang)
    2. {
    3. #ifdef _EDYUK_DEBUG_
    4. qDebug("setting language to : %s", qPrintable(lang));
    5. #endif
    6.  
    7. foreach ( QTranslator *t, translators )
    8. {
    9. QCoreApplication::removeTranslator(t);
    10. delete t;
    11. }
    12.  
    13. translators.clear();
    14.  
    15. QString suff = lang + ".qm";
    16. QDir dir(translationsPath());
    17.  
    18. QTranslator *qt = new QTranslator(this);
    19.  
    20. if ( qt->load("qt_" + lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)) )
    21. QCoreApplication::installTranslator(qt);
    22. else
    23. delete qt;
    24.  
    25. foreach ( QString s, dir.entryList(QDir::Files | QDir::Readable) )
    26. {
    27. //qDebug("entry : %s", qPrintable(s));
    28.  
    29. if ( !s.endsWith(suff) )
    30. continue;
    31.  
    32. //qDebug("translator found!");
    33.  
    34. QTranslator *t = new QTranslator(this);
    35.  
    36. if ( t->load(dir.filePath(s)) )
    37. {
    38. QCoreApplication::installTranslator(t);
    39. #ifdef _EDYUK_DEBUG_
    40. qDebug("successfuly loaded data from %s", qPrintable(dir.filePath(s)));
    41. #endif
    42. } else {
    43. delete t;
    44. #ifdef _EDYUK_DEBUG_
    45. qDebug("failed to load data from %s", qPrintable(dir.filePath(s)));
    46. #endif
    47. }
    48. }
    49.  
    50. pMenu->setTitle(tr("Language"));
    51.  
    52. sLang = lang;
    53. setValue("last", sLang);
    54.  
    55. emit languageChanged(sLang);
    56.  
    57. QEvent e((QEvent::Type)Edyuk::RunTimeTranslation);
    58. QCoreApplication::sendEvent(qApp, &e);
    59. }
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by wysota View Post
    BTW. You can try loading the .ts file instead of .qm. And what does installTranslator report?
    Do you mean that I would not have to generate a .qm from the .ts but just load the .ts as is? Are you sure this would work?
    Current Qt projects : QCodeEdit, RotiDeCode

  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: Fall back to untranslated mode

    Quote Originally Posted by fullmetalcoder View Post
    Here comes the code :
    So which part is responsible for loading the "untranslated" catalog? From what I see you try to install every possible translator at once.

    Are you sure this would work?
    Yes.

    Your code is a bit strange... Try this:

    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. QTranslator translator; // search in current directory
    4. translator.load("test_en"); // ignore the suffix
    5. app.installTranslator(&translator);
    6. b.setText(QObject::tr("Testing"));
    7. b.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Fall back to untranslated mode

    Quote Originally Posted by wysota View Post
    So which part is responsible for loading the "untranslated" catalog? From what I see you try to install every possible translator at once.
    This code is in charge of switcing the current language. It removes all previous translators and installs new one. There's no specific code in charge of "untranslation" but specific .ts and .qm files instead...

    Your code is a bit strange... Try this:

    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. QTranslator translator; // search in current directory
    4. translator.load("test_en"); // ignore the suffix
    5. app.installTranslator(&translator);
    6. b.setText(QObject::tr("Testing"));
    7. b.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 
    I'm not trying to translate... it works well already The wrong thing is that despite removing previous translators and installing new stub ones I can't seem to fallback to untranslated mode...
    Current Qt projects : QCodeEdit, RotiDeCode

  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: Fall back to untranslated mode

    That's why I ask you to try with my code... there is no such thing as "untranslated" mode. There always is a translation (of course if you use tr() calls), even if you don't provide any. Try loading an "empty" translation catalog (note my "en" suffix) and see if it works properly (especially if "load" returns true).

  11. #11
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Fall back to untranslated mode

    Quote Originally Posted by wysota View Post
    There always is a translation (of course if you use tr() calls)
    The point is, and I can confirm this happens even with a translation loaded, a string that IS NOT handled by current translators WILL BE handled by old translators EVEN IF they have been REMOVED and DESTROYED... This is merely what I call a bug... Does anyone know a way to prevent such thing to happen?
    Current Qt projects : QCodeEdit, RotiDeCode

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.