Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [ Resolved ] QTranslator and UTF-8 combo give me trouble
Qt 6.11 is out! See what's new in the release blog

[ Resolved ] QTranslator and UTF-8 combo give me trouble

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    (Using Qt 4.7.4 on Mac)

    My *.TS files are generated and are UTF-8 using a perl script I wrote. Long story with legacy dependency. We have 13 languages we have to support including some exotic ones. Generating *.QM files out of them seems to work well. You can load the *.QM file into Qt Linguist and everything looks healthy.

    Due to legacy reasons, my system langauge is "Enums". That is, I do something like this:

    @QString label = tr("APP_STRINGS_MYLABEL_TEXT"); // this translates to 13 langauges... @

    so, an excerpt from the english .TS file for instance reads:

    @<?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.0" language="en">
    <defaultcodec>UTF-8</defaultcodec>
    <context>
    <name>MyApp</name>
    <message>
    <source>APP_STRINGS_MYLABEL_TEXT/source>
    <translation>My Label Text In English</translation>
    </message>
    ..
    ..
    ..
    </context>@

    My project file has the following:
    @CODECFORTR = UTF-8@

    My main method has test code that looks like this:
    @QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTranslator translator;
    bool empty = translator.isEmpty(); // Returns TRUE
    bool loaded = translator.load("myApp_en","/Users/user/Dev/myApp/translation");
    empty = translator.isEmpty(); // returns FALSE

    // install the translator.
    MyApp->installTranslator(&translator);

    // Here comes my problem...
    QString test = MyApp->trUtf8("APP_STRINGS_MYLABEL_TEXT"); // returns "APP_STRINGS_MYLABEL_TEXT"
    QString test2 = MyApp->tr("APP_STRINGS_MYLABEL_TEXT"); // returns "APP_STRINGS_MYLABEL_TEXT"@

    As you can see, all my strings are being translated back to their original values. No real translation takes place. If you have any idea why thins might be happening, i'd appreciate the assistance. I am at a loss right now.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      The culprit was the context. Since I am using generated strings from a 3rd party source, the context was always wrong. As soon as I started using the "MyApp" context explicitly in the translate API it started working.

      thanks to all those who responded.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved