A doubt about translating with gettext

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ignatius881
Forum Newbie
Posts: 17
Joined: Thu Jul 14, 2011 9:09 am
Location: Oviedo (Spain)

A doubt about translating with gettext

Post by Ignatius881 »

Hello.

Well, I've a doubt. I know that, when you put a sentence in gettext, you can translate it into every language you want. But look at this example:

Code: Select all

echo "<B>"; echo _("Partido político creado correctamente."); echo "</B>";
echo '  '; echo _('Click'); echo ' <a href="user.php?mod=partidos">'; echo _("aquí"); echo '</a> '; echo _('para volver.'); echo '';
The text is in Spanish. Now, with this code, how should I be able to translate it into Japanese, for example? Mi doubt is related to the word order, etc.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: A doubt about translating with gettext

Post by Christopher »

gettext does not translate the text. If only looks up and returns a translation related to an exiting string it knows. If it has a translation into Japanese for 'aqui' then it will return that text. If you are trying to build sentences with translated words you will have word order problems. You need to have translations of complete phrases or sentences.
(#10850)
Ignatius881
Forum Newbie
Posts: 17
Joined: Thu Jul 14, 2011 9:09 am
Location: Oviedo (Spain)

Re: A doubt about translating with gettext

Post by Ignatius881 »

Well, I've found another solution. It's:

Code: Select all

echo ' <a href="user.php?mod=partidos">'._("Click aquí para volver.").'</a>'
:D

Now, I've another problem. Here is another piece of code:

Code: Select all

function duration($t) {

            if($t > 10713600)  { $d = round($t / 5356800) . ' years'; }
        elseif($t > 5356800)  { $d = '1 year'; }
        elseif ($t > 2626560) { $d = round($t / 2626560) . ' months'; }
        elseif ($t > 129600) { $d = round($t / 86400) . ' days'; }
        elseif ($t > 86400) { $d = '1 day'; }
        elseif ($t > 7200) { $d = round($t / 3600) . ' hours'; }
        elseif ($t > 3600) { $d = '1 hour'; }
        elseif ($t > 60) { $d = round($t / 60) . ' min'; }
        else { $d = $t . ' sec'; }
        return $d;
}
Well, I want to do something like this: http://www.gnu.org/s/hello/manual/gette ... forms.html

But I don't know how. Can you help me?
Post Reply