3

I have my fist Ubuntu Touch QML app running, and I am willing to translate it. Whenever I use a UI string in the qml files, I was careful to use i18n.tr("my text").

So now I need to generate the pot, po, and mo files. I found this question and a relevant answer, even if I'm not sure this is up to date (for example, the screenshot taken by zeokila does not correspond to what I see in my QtCreator version...?).

Maybe a comprehensive howto exists ?

So my question is specifically this:

how can strings in ListElement properties be taken into account by xgettext when generating the pot file ?

I cannot use i18n.tr here, as this results in a "ListElement: cannot use script for property value" error.

With plain Qt qsTr() and lupdate, you can use QT_TR_NOOP() to make these strings visible to lupdate.

How to do it with xgettext ?

alci
  • 5,979

1 Answers1

4

The only workaround for the "ListElement: cannot use script for property value" error that I know is to rely on the dynamicRoles property:

import QtQuick 2.0
import Ubuntu.Components 0.1


Rectangle {
    width: 200 // this is a property
    height: 200

    Item{
        ListModel {
            id: myListModel;
            dynamicRoles: true
        }
        Component.onCompleted: {
            myListModel.append({ "name": i18n.tr("Hello") } )
            foo.text = myListModel.get(0).name;
        }
    }

    Item {
        Text {
            id: foo
            }
    }

     Button {
         anchors.centerIn: parent
         text: i18n.tr("Press me")
     }

}

Creating the ListElement that way allow you to call i18n.tr() and xgettext correctly adds it to the pot file:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-06-03 18:19+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: foo.qml:15
msgid "Hello"
msgstr ""

#: foo.qml:28
msgid "Press me"
msgstr ""