11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

#<br />

# Il comando:<br />

# gettext -s "I like <strong>Bash</strong>"<br />

# estrae la stringa correttamente, mentre . . .<br />

# xgettext -s "I like <strong>Bash</strong>"<br />

# . . . fallisce!<br />

# ’xgettext’ restituisce "-s" perché<br />

#+ il comando estrae semplicemente solo<br />

#+ il primo argomento che incontra dopo la parola ’gettext’.<br />

Appen<strong>di</strong>ce I. Localizzazione<br />

# Caratteri <strong>di</strong> escape:<br />

#<br />

# Per localizzare una frase come<br />

# echo -e "Hello\tworld!"<br />

#+ si deve usare<br />

# echo -e "‘gettext \"Hello\\tworld\"‘"<br />

# Il "doppio carattere <strong>di</strong> escape" prima della ‘t’ è necessario per<br />

#+ consentire a ’gettext’ <strong>di</strong> cercare la stringa: ’Hello\tworld’<br />

# In questo modo gettext interpreta una ‘\’ letteralmente)<br />

#+ restituendo una stringa del tipo "Bonjour\tmonde",<br />

#+ così che il comando ’echo’ possa visualizzare il messaggio correttamente.<br />

#<br />

# Non si deve usare<br />

# echo "‘gettext -e \"Hello\tworld\"‘"<br />

#+ a causa del problema <strong>di</strong> xgettext spiegato prima.<br />

# Proviamo a localizzare la seguente riga <strong>di</strong> co<strong>di</strong>ce:<br />

# echo "-h <strong>di</strong>splay help and exit"<br />

#<br />

# Come prima soluzione, si potrebbe fare in questo modo:<br />

# echo "‘gettext \"-h <strong>di</strong>splay help and exit\"‘"<br />

# Così ’xgettext’ funziona correttamente,<br />

#+ mentre il programma ’gettext’ avrebbe interpretato "-h" come un’opzione!<br />

#<br />

# Una possibile soluzione sarebbe<br />

# echo "‘gettext -- \"-h <strong>di</strong>splay help and exit\"‘"<br />

# Così ’gettext’ funziona,<br />

#+ mentre ’xgettext’ avrebbe estratto "--", come già spiegato.<br />

#<br />

# Un espe<strong>di</strong>ente per localizzare la stringa è<br />

# echo -e "‘gettext \"\\0-h <strong>di</strong>splay help and exit\"‘"<br />

# Abbiamo aggiunto un \0 (NULL) all’inizio della frase.<br />

# In questo modo ’gettext’ funziona correttamente, come ’xgettext.’<br />

# Inoltre, il carattere NULL non mo<strong>di</strong>fica il comportamento<br />

#+ del comando ’echo’.<br />

# ------------------------------------------------------------------------<br />

788

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!