Come aggiungere una nuova stringa a un file .po o .pot?

2 nov 2010, 14:51:39
Visualizzazioni: 15.2K
Voti: 5

Ho un file .pot incluso nel mio tema WordPress. Ora voglio aggiungere stringhe che non erano presenti nel tema originale. Come posso fare? Devo aggiornare il file .pot? Ma 1) Come si fa esattamente? e 2) Come posso assicurarmi che le stringhe già tradotte non vengano cancellate? (Attualmente sto usando Poedit e non vedo un'opzione per aggiungere stringhe.)

2
Commenti

Penso che questa domanda non sia sufficientemente specifica per WordPress da rimanere su questo sito, quindi forse dovresti ripubblicarla su Stack Overflow, o magari su Super User (dato che menzioni anche un programma).

Jan Fabry Jan Fabry
2 nov 2010 15:42:42

@Jan Ho modificato la domanda in modo che sia più orientata a WordPress e non specifica per un programma

Lea Cohen Lea Cohen
3 nov 2010 11:49:00
Tutte le risposte alla domanda 4
1

Sto utilizzando http://wordpress.org/extend/plugins/codestyling-localization/ Ti consiglio di dargli un'opportunità :)

3 nov 2010 00:19:14
Commenti

Questo link al plugin non funziona più. Qualcuno ha delle alternative?

User User
21 lug 2016 00:36:52
0

Ecco uno script shell per generare automaticamente i file pot. Modifica il copyright, ecc. in base alle tue esigenze:

#!/bin/sh
#
# Autore: Denis de Bernardy <http://www.mesoconcepts.com>
# Versione: 0.1
# Licenza GPL
#
# Creato da Ryan Boren
# Codice successivo e patch da
# Kimmo Suominen (più) e Nikolay Bachiyski (meno)
# Denis de Bernardy

cwd=`pwd`

if [ -n "$1" ];
then
    cd "$1" || exit 1
    slug=`basename $1`
    dir=$cwd/$slug
else
    dir=$cwd
    slug=`basename $cwd`
fi

pot_file=$slug.pot

cp /dev/null "$dir/$pot_file"

find . -name '*.php' -print \
| sed -e 's,^\./,,' \
| sort \
| xargs xgettext \
    --keyword=__ \
    --keyword=_e \
    --keyword=_c \
    --keyword=__ngettext:1,2 \
    --keyword=_n:1,2 \
    --default-domain=$slug \
    --language=php \
    --output="$dir/$pot_file" \
    --join-existing \
    --from-code utf-8 \
    --copyright-holder='Mesoconcepts <http://www.mesoconcepts.com>' \
    --msgid-bugs-address=https://tickets.semiologic.com

# sostituisce solo l'ANNO nel messaggio di copyright (la seconda riga)
sed -i '' -e '2s/YEAR/'`date +%Y`'/' "$pot_file"

# e la ciliegina sulla torta - estrae la versione usando la magia - versoextracanus!~

if [ -f $dir/style.css ];
then
    name=`fgrep -i 'Theme Name:' $dir/style.css`
    version=`fgrep -i 'Version:' $dir/style.css`
elif [ -f $dir/$slug.php ];
then
    #statements
    name=`fgrep -i 'Plugin Name:' $dir/$slug.php`
    version=`fgrep -i 'Version:' $dir/$slug.php`
else
    name=$slug
    version=
fi

name=${name##*:}
name=${name##[[:space:]]}
version=${version##*:}
version=${version##[[:space:]]}
version=${version%%[[:space:]]*}

if [ "$name" != '' ];
then
    sed -i '' -e "1s/^# SOME DESCRIPTIVE TITLE/# $name pot file/" "$pot_file"
    sed -i '' -e "s/\(^#.*\)PACKAGE\(.*\)/\1$name\2/g" "$pot_file"
fi

if [ "$version" != '' ];
then
    sed -i '' -e "s/\(Project-Id-Version: \)PACKAGE VERSION/\1$version/" "$pot_file"
fi

cd "$cwd"

Utilizzo, supponendo un sistema *nix (Mac o Linux):

  • posiziona il codice sopra in ~/bin/gen_pot.sh e rendilo eseguibile
  • assicurati che ~/bin sia nel tuo $PATH
  • in wp-content/themes, esegui gen_pot.sh tuotema
  • oppure dalla directory del tuo tema, esegui gen_pot.sh
  • produrrà automaticamente il file pot...
2 nov 2010 15:44:31
0

Ecco una buona idea. Con iCanLocalize, puoi creare automaticamente un file .po.

Questo generatore analizzerà i file PHP e creerà file .po, utilizzati per la localizzazione. Estrae tutte le stringhe racchiuse nelle chiamate __("testo", "dominio") e _e("testo", "dominio").

Le stringhe possono essere racchiuse tra virgolette doppie (") o singole (') e con qualsiasi codifica di caratteri.

4 feb 2013 13:24:59
1

Se hai WP-CLI installato (interfaccia a riga di comando per WordPress), puoi ottenere questo risultato con il seguente comando:

wp i18n make-pot --merge source_dir target.pot

31 gen 2021 08:35:57
Commenti

Benvenuto su WPSE e grazie per aver dedicato del tempo a rispondere. Detto questo, non sono sicuro che questa risposta risolva le domande. Potresti per favore aggiungere un po' più di contesto o spiegare come questa risposta sarebbe una risposta appropriata?

Celso Bessa Celso Bessa
31 gen 2021 16:52:57