Opened 21 months ago
Last modified 4 weeks ago
#57981 new defect (bug)
Export .po files error of untranslated strings starting or ending with new lines (\n)
Reported by: | pedromendonca | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 2.8 |
Component: | I18N | Keywords: | has-patch |
Focuses: | Cc: |
Description
As found while dealing with GlotPress [see GitHub issue]https://github.com/GlotPress/GlotPress/issues/1594, there is a bug on the method export_entry()
of class PO
of core.
The PO method match_begin_and_end_newlines()
has an early check for $translation
, early returns the variable without changing nothing if the variable is ''
(empty).
As match_begin_and_end_newlines()
is only early returning for ''
(empty) values, fails and actually adds new lines on null
translations, which is wrong, and produces the undesired effect as seen in the GlotPress export error mentioned above.
The problem is that when the translation don't exist, it's set to null
, not ''
(empty). But export_entry()
sends to match_begin_and_end_newlines()
either ''
(empty) in case $entry->translations
is empty, or, of the translations array do exist, each one might have null
values, which is the correct default behavior.
So, for consistency probably match_begin_and_end_newlines()
should only check for null
values to earlier return, and the export_entry()
should only sends null
or non-empty strings in case there is an actual translation.
Change History (6)
This ticket was mentioned in PR #4260 on WordPress/wordpress-develop by @pedromendonca.
21 months ago
#1
- Keywords has-patch added
#2
@
21 months ago
- Keywords has-patch removed
Another options to what I've suggested in the PR:
- Leave the
export_entry()
untouched and make sure thematch_begin_and_end_newlines()
checks both fornull
and''
(empty) values. - Use
strval( $translation )
to make sure that only strings are sent tomatch_begin_and_end_newlines()
, cleaning up anynull
$translation values.
But I think it wouldn't be as simpler as I've made in the PR.
Thoughts on this would be appreciated.
@pedromendonca commented on PR #4260:
21 months ago
#3
@mukeshpanchal27 another options to what I've suggested in the PR:
- Leave the
export_entry()
untouched and make sure thematch_begin_and_end_newlines()
checks both fornull
and''
(empty) values. - Use
strval( $translation )
to make sure that only strings are sent tomatch_begin_and_end_newlines()
, cleaning up anynull
$translation values.
But I think it wouldn't be as simpler as I've made in the PR.
Thoughts on this would be appreciated.
Make
export_entry()
only send$translation
tomatch_begin_and_end_newlines()
, eithernull
if don't exist, or non-empty string if exist. And makematch_begin_and_end_newlines()
early return fornull
values instead of''
(empty), which is wrong and gives wrong exports as reported in https://github.com/GlotPress/GlotPress/issues/1594Trac ticket: https://core.trac.wordpress.org/ticket/57981