├── .gitignore ├── README.md ├── composer.json ├── src └── smmoosavi │ └── util │ └── gettext │ └── L10n.php └── test ├── locale ├── en_US │ └── LC_MESSAGES │ │ ├── messages.mo │ │ └── messages.po └── fa_IR │ └── LC_MESSAGES │ ├── messages.mo │ └── messages.po └── test.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # php-gettext 2 | 3 | Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system. 4 | 5 | ## How to Install 6 | 7 | #### Using [Composer](http://getcomposer.org/) 8 | 9 | Create a composer.json file in your project root: 10 | 11 | ```json 12 | { 13 | "require": { 14 | "smmoosavi/php-gettext": "dev-master" 15 | } 16 | } 17 | ``` 18 | 19 | Then run the following composer command: 20 | 21 | ```bash 22 | $ php composer.phar install 23 | ``` 24 | 25 | 26 | ## How to use 27 | 28 | ### Create translate files 29 | 30 | ``` 31 | . 32 | ├── composer.json 33 | ├── composer.lock 34 | ├── locale 35 | │   ├── en_US 36 | │   │   └── LC_MESSAGES 37 | │   │   ├── messages.mo 38 | │   │   └── messages.po 39 | │   └── fa_IR 40 | │   └── LC_MESSAGES 41 | │   ├── messages.mo 42 | │   └── messages.po 43 | ├── test.php 44 | └── vendor 45 | ├── autoload.php 46 | ... 47 | ``` 48 | 49 | 50 | ### php code 51 | 52 | 53 | ```php 54 | \n" 76 | "Language-Team: LANGUAGE \n" 77 | "MIME-Version: 1.0\n" 78 | "Content-Type: text/plain; charset=UTF-8\n" 79 | "Content-Transfer-Encoding: 8bit\n" 80 | "X-Generator: Poedit 1.5.5\n" 81 | 82 | msgid "test" 83 | msgstr "تست" 84 | 85 | msgid "Hi" 86 | msgstr "سلام" 87 | ``` 88 | 89 | 90 | ### Converting .po to .mo 91 | 92 | ```bash 93 | $ msgfmt -cv -o locale/fa_IR/LC_MESSAGES/messages.mo locale/fa_IR/LC_MESSAGES/messages.po 94 | ``` 95 | 96 | ## TODO 97 | 98 | * Provide `ext-gettext`. You can track progress in `topic/provide-ext-gettext` branch. 99 | 100 | ## Note 101 | 102 | Thank Danilo Segan. [php-gettext 1.0.11](https://launchpad.net/php-gettext/trunk/1.0.11) used in this project 103 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "smmoosavi/php-gettext", 3 | "description": "Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.", 4 | "authors": [ 5 | { 6 | "name": "Seyyed Morteza Moosavi", 7 | "email": "se.mo.moosavi@gmail.com" 8 | } 9 | ], 10 | "require": { 11 | "php": ">=5.3.0", 12 | "smmoosavi/php-gettext-core": "1.0.*" 13 | }, 14 | "autoload": { 15 | "psr-0": { 16 | "smmoosavi": "src/" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/smmoosavi/util/gettext/L10n.php: -------------------------------------------------------------------------------- 1 | translate($text); 33 | } 34 | 35 | public static function ngettext($single, $pluar, $number) 36 | { 37 | if (is_null(self::$locale_reader)) { 38 | return $single; 39 | } 40 | return self::$locale_reader->ngettext($single, $pluar, $number); 41 | } 42 | } 43 | } 44 | namespace { 45 | use smmoosavi\util\gettext\L10n; 46 | 47 | function __($text) 48 | { 49 | return L10n::gettext($text); 50 | } 51 | 52 | function _gettext($text) 53 | { 54 | return L10n::gettext($text); 55 | } 56 | } -------------------------------------------------------------------------------- /test/locale/en_US/LC_MESSAGES/messages.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smmoosavi/php-gettext/861a39e59ec2efa4deaa6a098957a506e610cf59/test/locale/en_US/LC_MESSAGES/messages.mo -------------------------------------------------------------------------------- /test/locale/en_US/LC_MESSAGES/messages.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: php-gettext 0.0.1\n" 4 | "Report-Msgid-Bugs-To: example@example.com\n" 5 | "POT-Creation-Date: 2010-05-28 06:18-0500\n" 6 | "PO-Revision-Date: 2013-08-07 11:34+0330\n" 7 | "Last-Translator: example translateor \n" 8 | "Language-Team: LANGUAGE \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Generator: Poedit 1.5.5\n" 13 | 14 | msgid "test" 15 | msgstr "test" 16 | 17 | msgid "Hi" 18 | msgstr "Hello" -------------------------------------------------------------------------------- /test/locale/fa_IR/LC_MESSAGES/messages.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smmoosavi/php-gettext/861a39e59ec2efa4deaa6a098957a506e610cf59/test/locale/fa_IR/LC_MESSAGES/messages.mo -------------------------------------------------------------------------------- /test/locale/fa_IR/LC_MESSAGES/messages.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: php-gettext 0.0.1\n" 4 | "Report-Msgid-Bugs-To: example@example.com\n" 5 | "POT-Creation-Date: 2010-05-28 06:18-0500\n" 6 | "PO-Revision-Date: 2013-08-07 11:34+0330\n" 7 | "Last-Translator: example translator \n" 8 | "Language-Team: LANGUAGE \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Generator: Poedit 1.5.5\n" 13 | 14 | msgid "test" 15 | msgstr "تست" 16 | 17 | msgid "Hi" 18 | msgstr "سلام" -------------------------------------------------------------------------------- /test/test.php: -------------------------------------------------------------------------------- 1 |