[Interest] get english translation

Rainer Wiesenfarth Rainer_Wiesenfarth at Trimble.com
Mon Sep 1 15:26:28 CEST 2014


From: Graham Labdon
> My application is internationalized, however, in some circumstances I need
> the English version of the string no matter what translator is being used.
> Anyone have any suggestions on how to achieve this?

One approach might be to subclass QTranslator and overwrite translate()
(snippet is untested!):

class MyTranslator : public QTranslator
{
public:
    MyTranslator (QObject *parent = 0)
        : QTranslator (parent)
        , m_translation (true)
    { }

    bool translation () const
    { return m_translation; }

    void setTranslation (bool translation)
    { m_translation = translation; }

    virtual QString translate (const char *context
        , const char *sourceText
        , const char *disambiguation = 0) const
    {
        return m_translation
            ? QTranslator::translate (context, sourceText, disambiguation)
            : QString (sourceText);
    }

private:
    bool m_translation;
};

However, setting or clearing the m_translation flag affects _all_ strings
that are passed through the translator, which might be not what you need. Of
course, more sophisitcated solutions may use the parameters given to
translate to decide what should be done...

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

-- 
Software Engineer | Trimble Geospatial
Rotebühlstraße 81 | 70178 Stuttgart | Germany
Office +49 711 22881 0 | Fax +49 711 22881 11
http://www.trimble.com/geospatial/ | http://www.inpho.de/

Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim
Eingetragen beim Amtsgericht Darmstadt unter HRB 83893,
Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6250 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140901/10c0f18a/attachment.bin>


More information about the Interest mailing list