Skip to content

Instantly share code, notes, and snippets.

@phil-lavin
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phil-lavin/ac3e3c20fd0e902f6f88 to your computer and use it in GitHub Desktop.
Save phil-lavin/ac3e3c20fd0e902f6f88 to your computer and use it in GitHub Desktop.

PO file at ./locale/en_US/LC_MESSAGES/foo.po:

msgid ""
msgstr ""
"Project-Id-Version: USA\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-01-29 12:04+0530\n"
"PO-Revision-Date: 2014-01-29 15:20+0530\n"
"Last-Translator: Phil <phil@hi.com>\n"
"Language-Team: TeamUSA <phil@hi.com>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-KeywordsList: lang;gettext;gettext_noop\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-Language: French\n"
"X-Poedit-Country: France\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"X-Poedit-SearchPath-0: .\n"

msgid "%d item"
msgid_plural "%d items"
msgstr[0] "%d Produkt"
msgstr[1] "%d Produkte"

MO file should be created with msgfmt at ./locale/en_US/LC_MESSAGES/foo.mo

Test script at ./test.php

<?
$directory = dirname(__FILE__).'/locale';
$domain = 'foo';
$locale ="en_US";

setlocale(LC_MESSAGES, $locale);
textdomain($domain);
bindtextdomain($domain, $directory);

$num = 1;
printf(ngettext('%d item', '%d items', $num), $num);
echo "\n";
echo ngettext('', '', $num);
?>

Script's output:

1 Produkt
Project-Id-Version: USA
Report-Msgid-Bugs-To:
POT-Creation-Date: 2014-01-29 12:04+0530
PO-Revision-Date: 2014-01-29 15:20+0530
Last-Translator: Phil <phil@hi.com>
Language-Team: TeamUSA <phil@hi.com>
Language:
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Poedit-KeywordsList: lang;gettext;gettext_noop
X-Poedit-Basepath: .
X-Poedit-Language: French
X-Poedit-Country: France
X-Poedit-SourceCharset: UTF-8
Plural-Forms: nplurals=2; plural=(n != 1)
X-Poedit-SearchPath-0: .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment