PoItem::formatSingular doesn't add linebreak on untranslated strings

Created on 3 May 2022, about 3 years ago
Updated 28 April 2025, 2 months ago

Problem/Motivation

When using PoItem to export translation strings, the linebreak output differs between translated and untranslated strings.

Steps to reproduce

$untranslated = new PoItem();
$untranslated->setSource("");

// msgid ""
// msgstr ""
$untranslated->__toString():

$translated = new PoItem();
$translated->setSource("");
$translated->setTranslation("");

// msgid ""
// msgstr ""
//
$translated->__toString();

Proposed resolution

Append line break to singular untranslated string output for consistency with other cases.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component

locale.module

Created by

πŸ‡¨πŸ‡¦Canada gapple

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    having a terrible time rebasing this lol

  • @andypost opened merge request.
  • πŸ‡«πŸ‡·France andypost

    Used to run test for 11.x and cherry-picked commit from previous MR (thanks smustgrave for 9.5)

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Think this looks good now

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    There's so much odd code in this class...

        foreach ($this->translation as $i => $trans) {
          if (isset($this->translation[$i])) {
            $output .= 'msgstr[' . $i . '] ' . $this->formatString($trans);
          }
          else {
            $output .= 'msgstr[' . $i . '] ""' . "\n";
          }
        }
    

    Afaics if (isset($this->translation[$i])) { must be true. I'm not even sure what that code is try to do... - maybe handle the case where one of the plural forms is not translated.

    Anyhow this fix is fine.

    • alexpott β†’ committed be9783de on 11.x
      Issue #3278481 by andypost, gapple, smustgrave: PoItem::formatSingular...
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    Going to commit to 11.x only as I don;t see why po files should change in a patch release. It's not like this is causing any real bugs.

    Committed be9783d and pushed to 11.x. Thanks!

Production build 0.71.5 2024