PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

[FIXED] How to preserve gettext() translations?

 September 01, 2022     gettext, internationalization, poedit, translation     No comments   

Issue

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?


Solution

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


Answered By - tialaramex
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing