Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Call to undefined function __()

    Premetto che conosco ben poco il PHP.

    Sto lavorando su un tema per WordPress e vorrei modificare una stringa per adattarla alla traduzione (avendo un file POT/PO a disposizione).

    Tale stringa si presenta così:
    Codice PHP:
    {
    if (
    $send)
    echo 
    '<div class="column col-2"><h2>Your message has been sent!</h2><div class="confirm">
    <p class="textconfirm">Thank you for contacting us.
    We will get back to you within 2 business days.</p>
    </div></div>'
    ;
    else
    echo 
    '<div class="column col-2"><h2>Oops!</h2><div class="confirm">
    <p class="texterror">Due to an unknown error, your form was not submitted, please resubmit it or try later.</p>
    <code>'
    .$buffer.'</code>
    </div></div>'


    Per la mia traduzione l'ho fatta diventare così:
    Codice PHP:
    {
    if (
    $send)
    echo 
    '<div class="column col-2"><h2>' __('Your message has been sent!''miotema') . '<div class="confirm">
    <p class="textconfirm">Thank you for contacting us.
    We will get back to you within 2 business days.</p>
    </div></div>'
    ;
    else
    echo 
    '<div class="column col-2"><h2>Oops!</h2><div class="confirm">
    <p class="texterror">Due to an unknown error, your form was not submitted, please resubmit it or try later.</p>
    <code>'
    .$buffer.'</code>
    </div></div>'


    Quindi il "Your message has been sent!" l'ho fatto diventare
    Codice PHP:
    ' . __('Your message has been sent!', 'miotema') . ' 
    E siccome sto sbagliando qualcosa mi viene fuori questo errore:
    Fatal error: Call to undefined function __() in /home/miosito/public_html/wp-content/themes/miotema/file.php on line 89
    Mi sembra un errore comune ma non riesco a venirne a capo.

  2. #2
    perche' se __ e' una stringa e non la metti tra apici viene scambiata per una funzione.

    Cos'e' __ ????

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  3. #3
    Guarda, qui spiega come predisporre un tema WordPress per la traduzione:
    http://codex.wordpress.org/Translating_WordPress

    Cito solo una parte:
    WordPress's developers chose to use the GNU gettext localization framework to provide localization infrastructure to WordPress. gettext is a mature, widely used framework for modular translation of software, and is the de facto standard for localization in the open source/free software realm.

    gettext uses message-level translation — that is, every "message" displayed to users is translated individually, whether it be a paragraph or a single word. In WordPress, such "messages" are generated, translated, and used by the WordPress PHP files via two PHP functions. __() is used when the message is passed as an argument to another function; _e() is used to write the message directly to the page. More detail on these two functions:

    __($message)
    Searches the localization module for the translation of $message, and passes the translation to the PHP return statement. If no translation is found for $message, it just returns $message.
    _e($message)
    Searches the localization module for the translation of $message, and passes the translation to the PHP echo statement. If no translation is found for $message, it just echoes $message.
    Quindi se avessi avuto del semplice HTML tipo:
    codice:
    <div>Your message has been sent!</div>
    , la mia traduzione sarebbe diventata effettiva con questo codice:
    Codice PHP:
    <div><?php _e('Your message has been sent!'?></div>
    Invece (se ho capito bene), dentro un codice PHP dovrei usare sto __() .

  4. #4
    PS.
    In definitva __() è una funzione PHP.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.