Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eusonlito/gettext
A Simple Gettext Interface
https://github.com/eusonlito/gettext
Last synced: 6 days ago
JSON representation
A Simple Gettext Interface
- Host: GitHub
- URL: https://github.com/eusonlito/gettext
- Owner: eusonlito
- Created: 2012-08-22T13:39:22.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2012-09-05T11:49:03.000Z (about 12 years ago)
- Last Synced: 2024-10-18T04:23:06.358Z (26 days ago)
- Language: PHP
- Size: 105 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Gettext
=====This script works as simple interface to load and print gettext translations
Usage
--------
setPath(__DIR__.'/languages/');# if yours languages files are into folders (languages/en/gettext.mo, languages/es/gettext.mo)
$Gettext->init();# else if yours languages files are files (languages/en.mo, languages/es.mo)
$Gettext->init(true);$Gettext->setLanguage('en');
# now you can execute gettext print functions
# return string
echo __('Hi! This text (translated or not)');# prints directly
__e('Another text :)');# Added language cookie store
# https://github.com/eusonlito/Cookie
include (__DIR__.'/libs/ANS/Cookie/Cookie.php');$Cookie = new \ANS\Cookie\Cookie;
$Cookie->setSettings(array(
'name' => 'language'
));$Gettext = new \ANS\Gettext\Gettext;
$Gettext->setPath(__DIR__.'/languages/');
$Gettext->setCookie($Cookie, 'language');
$Gettext->setDefaultLanguage('en');# if yours languages files are into folders (languages/en/gettext.mo, languages/es/gettext.mo)
$Gettext->init();# else if yours languages files are files (languages/en.mo, languages/es.mo)
$Gettext->init(true);# update language
if (isset($_GET['language'])) {
$Gettext->setLanguage($_GET['language'], true);
}