How to preserve gettext() translations? - internationalization

Suppose I have a example.php file like that:
<p>
<?php echo _('Hello world') ?>
</p>
<p>
<b><?php echo _('the end') ?>
</p>
If I extract strings:
xgettext example.php
I get a messages.mo file, that I can open with poedit, translate, create a .po file, etc. That's ok, the problem is when I edit my original and already translated example.php:
<p>
<?php echo _('Hello world') ?>
</p>
<p>
<?php echo _('new string') ?>
</p>
<p>
<b><?php echo _('the end') ?>
</p>
I've added a new string and if I execute xgettext again I get a messages.mo file where all strings are empty, so I have to use poedit and translate again all strings. How can I re-use my previous translations?

You can merge two po files together with msgmerge. If the source string is unchanged the merge should work perfectly, if it has changed you obviously may have to do some work to get things translated again, and of course you will have to translate any entirely new strings.
msgmerge -o results.po my_existing_translations.po untranslated_xgettext_output.po

Related

How can we fetch images from database to dashboard using CodeIgniter 3

Image path is getting stored in the database and file is getting uploaded in the upload path but the image is not displaying in the tabular format.
Here is the code for the view:
<tbody>
<?php
$query = $this->db->query("SELECT * FROM banner_mgmt LIMIT 1");
// $url = base_url().
foreach ($query->result() as $row)
{
echo "<tr>";
echo "<td>$row->id</td>";
echo "<td>$row->banner_name</td>";
echo "<td>".'<img src="base_url().$row->banner_image" style="height:150px; width:150px;" alt="not found">'."</td>";
echo "<td>$row->banner_image</td>";
echo "</tr>";
}
?>
</tbody>
Assuming that base_url().$row->banner_image does actually result in a correct path/image name...
You need to check your string concatenation.
What you have... (overly complicated)
echo "<td>".'<img src="base_url().$row->banner_image" style="height:150px; width:150px;" alt="not found">'."</td>";
What you should have...
echo '<td><img src ="'.base_url().$row->banner_image.'" style="height:150px; width:150px;" alt="not found"></td>';
You need to think about how you want the string to turn out, which helps you determine when and where to use ', " and . properly.
Here I am wrapping the string using ' (single quotes), which allows me to use " (double quotes) in the HTML properties without much effort.
Read up on how to use base_url() in the Codeigniter user guide...
So you could have
echo '<td><img src ="'.base_url($row->banner_image).'" style="height:150px; width:150px;" alt="not found"></td>';
You could even use " (double quotes) which evaluate php but you will need to escape any 'internal' double quotes you want to display.
echo "<td><img src =\"base_url($row->banner_image)\" style=\"height:150px; width:150px;\" alt=\"not found\"></td>";
So, you need to read the answer at What is the difference between single-quoted and double-quoted strings in PHP?

Unescaped pug attribute not processed by laravel blade

I'm using Laravel Pug https://github.com/BKWLD/laravel-pug, and the file is named *.pug.blade.php. I'm trying to set an attribute value.
| <?php $x = "any"; ?>
div(class!="{{ $x }}")
| {{ $x }}
the output html is
<div class="{{ $x }}">any</div>
Interestingly, in attribute, the php variable is accessed with no < ? php ? > or {{ }} enclosures, just like javascript variables
| <?php $x = "any"; ?>
div(class=$x)
| {{ $x }}
the HTML output
<div class="any">any</div>
Also, the dollar sign can be omitted, and interpolation can be used
| <?php $x = "any"; ?>
div(class = x + "test")
| {{ $x }}
the HTML output
<div class="anytest">any</div>

Remove some text between tags from HTML file

I have multiple HTML files, like this:
</HEAD><BODY><B> something <BR>bla bla bla
<A HREF=http://www.exemple.com>http://exemple.com</A> - site bla
bla bla bla (test n°15336) <BR><BR><BR><HR>
I want to make it like this:
</HEAD><BODY><B> something <BR> <BR><BR><BR><HR>
Nothing works: sed, grep, awk... any suggestions?
I am back to post the solution after long search
first i need to parsing my html file so i have create a php code that finish this task very simple and useful
<?php
define('TEMPLATE', __DIR__ . DIRECTORY_SEPARATOR . 'test.html');
$template = file_get_contents(TEMPLATE);
$st='';
$template = preg_replace('#(<\/A>).*?(<BR>)#is', $st, $template);
$template = preg_replace('#(<BR>).*?(<BR>)#is', $st, $template);
$file = 'output.html';
file_put_contents($file, $template);
?>
Et Voila!!!!!! XD
Thank you for the Reputation and thank you again for no Helping .

for loop not working in generate html file via bash script

When I am running following bash script-
#!/bin/bash
items="b.js
a.js
c.js"
startScript='<script src="'
endScript='"></script>'
for item in $items
do
echo $startScript$item$endScript
done
Output:
<script src="c.js"></script>
<script src="a.js"></script>
<script src="b.js"></script>
I want to run this for loop inside generated html file via a bash script. For loop is not working here.
#!/bin/bash
items="b.js
a.js
c.js"
startScript='<script src="'
endScript='"></script>'
cat << noEcho
<HTML>
<HEAD>
<TITLE> Bash Script </TITLE>
</HEAD>
<BODY>
for item in $items
do
echo $startScript $item $endScript
done
</BODY>
</HTML>
noEcho
Simple example with the most glaring bugs fixed:
#!/bin/bash
files=( b.js a.js c.js)
startScript='<script src="'
endScript='"></script>'
cat << noEcho
<html><head><title>Bash Script</title></head><body>
$(
for file in "${files[#]}"; do
echo "${startScript}${file}${endScript}"
done
)
</body></html>
noEcho
You can see the above running, with its output, at http://ideone.com/rSsO9H.
Some notes:
Don't do this. Really. Use a real template language that understands HTML syntax and knows how to escape content properly; you'll find securing this kind of code next to impossible if/when dealing with dynamic data.
Strings are not arrays. If you want an array, use an actual array.
If you want the output of a given piece of code to be substituted into a string (or, in this case, a heredoc), it needs to be in a command substitution: $()

Pass a variable to a template .phtml block in Magento

This code is write in market.phtml
<?php echo $this->getLayout()->createBlock('core/template')->setData('vendorId',$vendor->getCustomerId())->setTemplate('marketplace/vendors/badge.phtml')->toHtml();?>
In Badge.php
echo $this->vendorId;
But my output is null. Is this correct way to pass data to block?
You need to change your variable like this and check it
<?php echo $this->getLayout()->createBlock('core/template')->setVendorId($vendor->getCustomerId())->setTemplate('marketplace/vendors/badge.phtml')->toHtml();?>
Now you can access this vendor ID variable in badge.phtml file like this :
<?php echo $this->getVendorId();?>

Resources