0

This little application make some problems:

int main(int argc, char *argv[])
{
  QTranslator* translator = new QTranslator();
  QString langCode = "en_GB";
  translator->load(QString("Core_%1.qm").arg(langCode));
  QCoreApplication::installTranslator(translator);

  auto now = QDateTime::currentDateTime();
  qDebug() << now.toString(tr("Timeformat"));

  return 0
}

For every language I create a separate Core.qm containing a translation for Timeformat. This is for "en_GB"

<message>
  <source>Timeformat</source>
  <translation>hh:mm ap</translation>
  <comment/>
</message>

And this is for "de_DE"

<message>
  <source>Timeformat</source>
  <translation>hh.mm</translation>
  <comment/>
</message>

The system language setting can be different then the loaded language file. If Software is running on a English laptop at 13:57 with loaded Core_de_DE.qm it displays 13.57. ANd with loaded Core_en_GB.qm it show 01:57 pm.

But when the Software running on a french laptop with loaded Core_en_GB.qm (because my Software has no french translation). The Software show 01:57 (the pm is missing). Why?

Marcus
  • 1,910
  • 2
  • 16
  • 27

1 Answers1

0

I've soled this by using the UK Local for every toString call instead of the system one:

//instead of
qDebug() << now.toString(tr("Timeformat"));
// I use now
qDebug() << QLocale("en_GB").toString(now, tr("Timeformat"));
Marcus
  • 1,910
  • 2
  • 16
  • 27