Skip to content

Conversation

suricactus
Copy link
Collaborator

@suricactus suricactus commented Jul 29, 2025

If there is Python code doing:

Object.tr("%n apple(s)", None, 2)

And I run:

$ qgis-plugin-ci push-translation $TX_TOKEN

I get an exception:

transifex.api.exceptions.UploadException: English pluralized strings should contain 2 plurals. Instead, on string '<translation><numerusform/></translation>' we found 1

The produced output by pylupdate5 in the .ts file is:

<message numerus="yes">
  <source>%n apple(s)</source>
  <translation type="unfinished">
    <numerusform></numerusform>
  </translation>
</message>

We assume that the source language is English.

The problem is that English has 2 plural forms and they must be specified as part of the .ts file as two separate tags:

<message numerus="yes">
  <source>%n apple(s)</source>
  <translation type="unfinished">
    <numerusform></numerusform>
    <numerusform></numerusform>
  </translation>
</message>

While the suggested solution is far from beautiful and optimal, the other explored options did not work better:

  1. replace pylupdate5 with lupdate - according to the docs (https://doc.qt.io/qt-6/linguist-lupdate.html), lupdate should parse Python without an issue, but this is not the case, many errors due to failed Python parsing happened:
tr() cannot be called without context
Unterminated C++ string
  1. parsing the XML and adding the new tag looks like an overkill, so I stick with a simple search and replace. 3) removing the <numerusform></numerusform> from the .ts file caused:
transifex.api.exceptions.UploadException: English pluralized strings should contain 2 plurals. Instead, on string '<translation><numerusform/></translation>' we found 0
  1. seems that lupdate has a nice set of parameters that can help, but are not available in pylupdate5 even after looking at it's internals:
       -source-language <language>[_<region>]
              Specify/override the language of the source strings. Defaults to POSIX if not specified and the file does not name it yet.

       -target-language <language>[_<region>]
              Specify/override the language of the translation.  The target language is guessed from the file name if this option is not specified and the file contents name no language yet.

See it up and running here: https://github.com/opengisch/qfieldsync/actions/runs/16583706724/job/46904935929

If there is Python code doing:
```
Object.tr("%n apple(s)", None, 2)
```

And I run:
```
$ qgis-plugin-ci push-translation $TX_TOKEN
```

I get an exception:
```
transifex.api.exceptions.UploadException: English pluralized strings should contain 2 plurals. Instead, on string '<translation><numerusform/></translation>' we found 1
```

The produced output by `pylupdate5` in the `.ts` file is:
```
<message numerus="yes">
  <source>%n apple(s)</source>
  <translation type="unfinished">
    <numerusform></numerusform>
  </translation>
</message>
```

We assume that the source language is English.

The problem is that English has 2 plural forms and they must be specified as part of the `.ts` file as two separate tags:
```
<message numerus="yes">
  <source>%n apple(s)</source>
  <translation type="unfinished">
    <numerusform></numerusform>
    <numerusform></numerusform>
  </translation>
</message>
```

While the suggested solution is far from beautiful and optimal, the other explored options did not work better:

1) replace `pylupdate5` with `lupdate` - according to the docs (https://doc.qt.io/qt-6/linguist-lupdate.html), `lupdate` should parse Python without an issue, but this is not the case, many errors due to failed Python parsing happened:
```
tr() cannot be called without context
Unterminated C++ string
```
2) parsing the XML and adding the new tag looks like an overkill, so I stick with a simple search and replace.
3) removing the `<numerusform></numerusform>` from the `.ts` file caused:
```
transifex.api.exceptions.UploadException: English pluralized strings should contain 2 plurals. Instead, on string '<translation><numerusform/></translation>' we found 0
```
4) seems that `lupdate` has a nice set of parameters that can help, but are not available in `pylupdate5` even after looking at it's internals:
```
       -source-language <language>[_<region>]
              Specify/override the language of the source strings. Defaults to POSIX if not specified and the file does not name it yet.

       -target-language <language>[_<region>]
              Specify/override the language of the translation.  The target language is guessed from the file name if this option is not specified and the file contents name no language yet.

```
Copy link
Member

@3nids 3nids left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you checked with pylupdate6?

The fix doesn't seem sufficient to me in case this is fixed upstream. If there are 2 tags, we'll get 4, correct?

@3nids
Copy link
Member

3nids commented Jul 31, 2025

@suricactus could you update the PR to actually check if the file is incorrect before making the changes?

@suricactus
Copy link
Collaborator Author

suricactus commented Jul 31, 2025

I think it will always be incorrect in my understanding how pylupdate5 works. But yes, I can try to do that.

However, I don't see an easy way to achieve this without parsing the XML properly, so I can come back to this later this year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants