Traduzione e titoli

2 contenuti / 0 new
Ultimo contenuto
Anonimo (non verificato)
Ritratto di Anonimo
Traduzione e titoli

Ho installato la traduzione 4.5.0. Ok. Funziona. Ho lasciato italiano e inglese come lingue attivabili.

Piccolo probelma di dettaglio. Ho un blocco personale sulla home.
Come fare per avere il titolo del blocco visualizzato sulla pagina in funzione della lingua scelta?
Ho letto un post di matteo (http://drupal.org/user/724) su drupal.org su come fare un menu bilingue dentro un blocco ma non ho idea di come agire sul titolo.
Inoltre vedo che http://www.matteoferrari.org/ funziona proprio bilingue nei titoli.
Come si fa?

@matteo nel tuo post fai riferimento a funzione .t() .url() etc: dove trovo la documetazione

In Drupal qualsiasi stringa sia da tradurre DEVE essere specificata nella funzione t(), che ha come parametro il testo da tradurre e restituisce la stringa tradotta come output.
La funzione t() è in /includes/common.inc

/**
* Translate strings to the current locale.
*
* When using t(), try to put entire sentences and strings in one t() call.
* This makes it easier for translators. HTML markup within translation strings
* is acceptable, if necessary. The suggested syntax for a link embedded
* within a translation string is:
* @code
*   $msg = t('You must log in below or <a href="/dr474/%url">create a new
*             account</a> before viewing the next page.', array('%url'
*             => url('user/register')));
* @endcode
* We suggest the same syntax for links to other sites. This makes it easy to
* change link URLs if needed (which happens often) without requiring updates
* to translations.
*
* @param $string
*   A string containing the English string to translate.
* @param $args
*   An associative array of replacements to make after translation. Incidences
*   of any key in this array are replaced with the corresponding value.
* @return
*   The translated string.
*/

su Drupadocs trovi un esempio di blocco, dove trovi

$block['subject'] = t('Title of block #1');

function block_example_block($op = 'list', $delta = 0) {
  // The $op parameter determines what piece of information is being requested.
  if ($op == 'list') {
    // If $op is "list", we just need to return a list of block descriptions. This
    // is used to provide a list of possible blocks to the administrator.
    $blocks[0]['info'] = t('A simple text string');
    $blocks[1]['info'] = t('An empty block');
    return $blocks;
  }
  else if ($op == 'view') {
    // If $op is "view", then we need to generate the block for display purposes.
    // The $delta parameter tells us which block is being requested.
    switch ($delta) {
      case 0:
        // The subject is displayed at the top of the block. Note that it should
        // be passed through t() for translation.
        $block['subject'] = t('Title of block #1');
        // The content of the block is typically generated by calling a custom
        // function.
        $block['content'] = block_example_contents(1);
        break;
      case 1:
        $block['subject'] = t('Title of block #2');
        $block['content'] = block_example_contents(2);
        break;
    }
    return $block;
  }
}

La doc. su Drupal la trovi su www.drupaldocs.org.

Quando eseguirai il codice, Drupal creerà le stringhe da tradurre e imposterà le traduzioni a null nelle tabelle locales_source e locales_target.
Potrai a quel punto tradurre le stringhe teamite le funzioni di amministrazione di Drupal.

ATTENZIONE

Se devi tradurre un testo fisso, la funzione t() ha un solo argomento, e ti conviene scrivere esplicitamente la funzione come t('testo') nel sorgente.

Se devi tradurre qualcosa di dinamico, usa questa sintassi:

t('blocco di %parametro', array("%parametro" => $latuavariabile));

In questo modo, il tuo testo è aderente alle regole di creazione dei files .po, cioè il testo da tradurre non cambia anche se una parte del testo è dinamica.
Infatti, se il tuo blocco lo vuoi mettere in un modulo, puoi usare extractor.php per estrarre tutte le stringhe da tradurre da quel modulo e permettere ad altri di tradurlo nel loro linguaggio tramite il file .po

Spero di averti chiarito i dubbi.
Matteo

Matteo