Updated: Comment #11
Problem/Motivation
Exported translation files are not gettext-compatible when containing untranslated strings.
For reproducing it:
- Install in a non-English language.
- Translate any string.
- Export a PO file (checking "Include untranslated strings")
- Import the file again, a exception should not be thrown.
Proposed resolution
Empty translations must be between quotes.
Remaining tasks
Add tests.
Quote empty translations when exporting.
User interface changes
None.
API changes
None.
Related Issues
None.
Original report by [username]
When importing a .po file on admin/config/regional/translate/import, once the importation is completed, I get this message:
An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /drupal/batch?id=5&op=do_nojs&op=do
StatusText: OK
ResponseText: Recoverable fatal error: Argument 2 passed to Drupal\Component\Utility\String::format() must be of the type array, null given, called in /Users/outimunter/Sites/drupal/core/lib/Drupal/Component/Gettext/PoStreamReader.php on line 522 and defined in Drupal\Component\Utility\String::format() (line 89 of /Users/outimunter/Sites/drupal/core/lib/Drupal/Component/Utility/String.php).The translation is anyway imported and I can go ahead by clicking on the error page link.
The steps to produce this are:
- the site is installed in French
- on admin/config/regional/translate/import I import a .po file
- the options about treating the strings and overwriting can be checked or unchecked
- once the importation is completed, the error message appears
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | po-export-2029505-27.patch | 2.02 KB | gábor hojtsy |
| #27 | interdiff.txt | 726 bytes | gábor hojtsy |
| #21 | interdiff-19-21.txt | 678 bytes | yesct |
| #21 | po-export-2029505-21.only-test.must-fail.patch | 1.31 KB | yesct |
| #21 | po-export-2029505-21.patch | 1.95 KB | yesct |
Comments
Comment #1
gábor hojtsyMore specific title. Ajax recoverable errors can be many things.
Comment #2
penyaskitoComment #3
penyaskitoOuti, I tried with basque and french with the official .po files for core and could not reproduce your issue (drupal-8.0-alpha2.eu.po & drupal-8.0-alpha2.fr.po).
Which po files did you import? could you upload them to the issue?
Comment #4
penyaskitoJust talked with Outi: she translated some strings in the interface, exported the PO file and then tried to import it again.
Doing the same I can reproduce it.
Uploading exported/imported po file for the reference.
Comment #5
penyaskitoComment #6
penyaskitoFor empty strings that are exported , there are not quotes
So when parsing the file we report the error:
Recoverable fatal error: Argument 2 passed to Drupal\Component\Utility\String::format() must be of the type array, null given, called in /Users/outimunter/Sites/drupal/core/lib/Drupal/Component/Gettext/PoStreamReader.php on line 522 and defined in Drupal\Component\Utility\String::format() (line 89 of /Users/outimunter/Sites/drupal/core/lib/Drupal/Component/Utility/String.php).If we run gettext-lint to the exported file, we see that is not valid:
returns:
Comment #7
penyaskitoAs a confirmation, I checked an exported file with gtranslator (PO editor for gnome), and it crashed. Fixed the file manually and it worked.
Comment #8
penyaskitoAdding test coverage checking that the empty strings are properly quoted if non-translated strings are selected for exporting.
Quoting is done in PoItem itself.
Comment #9
yesct commentedWhy are you changing from February to March? Is it because the language in the test used to not have a translation for February, and now does... but it still does not have translation for March?
Comment #10
sutharsan commentedLooks good.
Comment #11
penyaskitotl;dr: February is not that bad...
Long version:
While testing this I wanted to test two different cases:
1. Importing a file with an unstranslated string (February)
2. Creating the string in locale storage (March)
but I noticed that in 1), nothing is imported and no string is saved into locale.storage, so it was not really needed.
Comment #12
yesct commentedThis looks better. :)
I'll try to reproduce.
Comment #13.0
(not verified) commentedUpdate summary.
Comment #13.1
penyaskitocore gates
Comment #14
penyaskito#11: po-export-2029505-10.only-tests.must-fail.patch queued for re-testing.
Comment #15
penyaskito#11: po-export-2029505-10.patch queued for re-testing.
Comment #16
gábor hojtsyThis lacks code comments as to what it is used for.
Comment #17
outi commentedI tested the export and import on a French and an English installation and it seems to be ok now.
Comment #18
outi commentedI tested the export and the import on a French and on an English installation, and it seems to work now.
Comment #19
penyaskitoRenamed the function to getUntranslatedString for readability and added docblock.
Comment #20
gábor hojtsyLooks all good now then :)
Comment #21
yesct commentedunstranslated
should be untranslated.
Also put it below 80 chars.. and added the @return.
Comment #22
penyaskitoIt was already RTBC by Gábor, and YesCT improved docs.
Comment #23
yesct commentedThis issue was RTBC and passing tests on July 1, the beginning of API freeze.
Comment #24
catchWhile we're here let's make the string concatenation follow coding standards.
Comment #25
yesct commentedHere is the reference to check:
https://drupal.org/coding-standards#concat
Comment #26
penyaskitoI'm not working on this at the moment, so any help is appreciated.
Comment #27
gábor hojtsyIncluded the whitespace fix that @catch requested. Also I checked the plural formatting as well, and it covers empty strings proper, so no such bug evident there.
Back to RTBC as per above given the minor whitespace change only.
Comment #28
yesct commentedyep. looks good.
Comment #29
gábor hojtsy#27: po-export-2029505-27.patch queued for re-testing.
Comment #30
alexpottCommitted b2b2a44 and pushed to 8.x. Thanks!
Comment #32
gábor hojtsyRemove sprint tag.
Comment #32.0
gábor hojtsySummary update