Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
I didn’t have to localize PHP projects , and even more so WordPress , using gettext , but the other day I did it with some bash scripts. Perhaps my experience will be helpful.
1. You need to define the domain and scope of the message files search.
The domain is set by the textdomain function , and the path to the resources is bindtextdomain .
bindtextdomain('example', './local');
textdomain('example');
echo gettext("Hello world!");
echo gettext("Test123");
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <[email protected]>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-01-15 14:55+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <[email protected]>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Hello world!"
msgstr ""
msgid "Test123"
msgstr ""
msgid "Hello world!"
msgstr "Привет, мир!"
msgid "Test123"
msgstr "Тест123"
#!/bin/bash
lang="$1"
path="$(cd "$(dirname "$0")" && pwd)"
if ; then
path="$path/$lang"
if ; then
mkdir "$path"
fi
fi
cd "$path"
find "$path" -name "*.po" | while read -r f; do
po_dir="$(dirname $f)"
po_file="$(basename $f)"
po_name="$(echo $po_file | cut -d'.' -f1)"
msgfmt --output-file="$po_dir/$po_name.mo" "$f" && \
printf "Created: $po_dir/$po_name.mo\n" || \
printf "ERROR: Could not create mo-file from: $f\n"
done
bindtextdomain('example', './local');
textdomain('example');
/local/ru/LC_MESSAGES/messages.mo
/local/en/LC_MESSAGES/messages.mo
/local/en_US/LC_MESSAGES/messages.mo
/local/ru_GB/LC_MESSAGES/messages.mo
/local/[Код культуры]/LC_MESSAGES/messages.mo
I don't see the point in these .po\.mo, especially for php.
store in a simple associative array - and easier (the file can be edited in any editor, without the need for compilation) and spends less resources.
For example, wordpress MO::import_from_reader and do not throw it away, and eats processor time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question