Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide gettext infos in php

I am writing simple script using gettext PHP function. All works well but i try to monitore what is changed for what.

For example when user change 2 fields

Type: (old) Agreement (new) Anex
Notes: (old) #empty field# (new) Agreement ID: 123

My editinfo generator looks like that

foreach($checkArray as $row => $value)
{
    if ($addData[$row] != $checkArray[$row])
    {
        $editInfo .= ' <b>' . _("FILED") . '</b> ' . _("$row") . ' <b>' . _("CHANGED FROM") . '</b> ' . _($checkArray[$row]) . ' <b>' . _("FOR") . '</b> ' . _($addData[$row]) . '<br />';
    }
}

But i recieved info like that

<b>POLE</b> Type <b>ZMIENIONE Z</b> Umowa <b>NA</b> Aneks <br />
<b>POLE</b> Notes <b>ZMIENIONE Z</b> Project-Id-Version: 
POT-Creation-Date: 
PO-Revision-Date: 
Language-Team: 
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Generator: Poedit 2.0.9
Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);
Last-Translator: 
Language: pl
 <b>NA</b> Agreement ID: 123<br />

As You can see all translates works well, but when field is empty, gettext function return some crazy stuff but i would like to have

<b>Pole</b> Type <b>ZMIENIONE Z</b> Umowa <b>NA</b> Aneks<br>
<b>Pole</b> Notes <b>ZMIENIONE Z</b> <b>NA</b> Agreement ID: 123<br>

So my question is what i should to change in PHP or PHP Settings in my server to hide that gettext info. I would to set "If gettext can't find translation just write pure text" in this case nothing.

Regards

like image 294
Emilian Avatar asked Nov 06 '22 20:11

Emilian


1 Answers

As we can read in gettext manual:

This also has another advantage, as the empty string in a PO file GNU gettext is usually translated into some system information attached to that particular MO file, and the empty string necessarily becomes the first in both the original and translated tables, making the system information very easy to find.

Probably your .po file contains msgid which is an empty string and its value is just the system information.

So when you call _("") you get that. You can try passing some default field if it's not found:

_($checkArray[$row] ?: "default")
like image 197
Karol Samborski Avatar answered Nov 14 '22 12:11

Karol Samborski