I have a .pot file that came with my Wordpress theme. Now I want to add strings to it, that weren't there in the original theme. How do I do that? Do I have to update the .pot file? but 1) How do I do that, and 2) How do I make sure that the strings that were translated won't get erased? (I'm currently using Poedit and I can't see a feature to add a string.)
-
I think this question is not WordPress-specific enough to stay on this site, so maybe you should re-post it on Stack Overflow, or maybe Super User (since you also mention a program).– Jan FabryNov 2, 2010 at 13:42
-
@Jan I edited the question so that it's more Wordpress oriented and not program specific– Lea CohenNov 3, 2010 at 9:49
4 Answers
I am using http://wordpress.org/extend/plugins/codestyling-localization/ Give it a chance i suggest :)
-
1This plugin link is dead. Anybody got any alternatives?– user66711Jul 20, 2016 at 21:36
Here's a shell script to generate pot files automatically. Modify the copyright, etc to fit your needs:
#!/bin/sh
#
# Author: Denis de Bernardy <http://www.mesoconcepts.com>
# Version: 0.1
# GPL licensed
#
# Created by Ryan Boren
# Later code and patches from
# Kimmo Suominen (more) and Nikolay Bachiyski (less)
# 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
# sub only the YEAR in the copyright message (the 2nd line)
sed -i '' -e '2s/YEAR/'`date +%Y`'/' "$pot_file"
# and the cherry of the pie - extract version using magic - 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"
Usage, assuming a *nix box (Mac or Linux):
- place the above in ~/bin/gen_pot.sh and make it executable
- make sure that ~/bin is in your $PATH
- in wp-content/themes, run gen_pot.sh yourtheme
- or from within in your theme's dir, run gen_pot.sh
- it'll output the pot file automatically...
Here's a good idea. With iCanLocalize, you can create a .po
file automatically.
This generator will scan PHP file(s) and create .po files, that are used for localization. It will extract all strings wrapped in
__("txt", "domain")
and_e("txt", "domain")
calls.Strings can be enclosed in either double quotes (") or single quotes(') and with any character encoding.
If you have WP-CLI installed (command-line interface for WordPress), this can be achieved with the following command:
wp i18n make-pot --merge source_dir target.pot
-
Welcome to WPSE and thanks for taking the time to answer. That said, I am not sure this answers the questions. Could you please add a little more of context or explaing how this answer would be an appropriated answer? Jan 31, 2021 at 14:52