Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/technicalguru/php-i18n
Provides localization features for PHP apps
https://github.com/technicalguru/php-i18n
i18n internationalization localization php
Last synced: 20 days ago
JSON representation
Provides localization features for PHP apps
- Host: GitHub
- URL: https://github.com/technicalguru/php-i18n
- Owner: technicalguru
- License: lgpl-3.0
- Created: 2020-11-12T07:33:08.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-30T10:02:18.000Z (about 2 years ago)
- Last Synced: 2024-10-07T01:03:32.626Z (about 1 month ago)
- Topics: i18n, internationalization, localization, php
- Language: PHP
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# php-i18n
Provides localization features for PHP apps. It reads a local i18n file for your application
and provides localized values for keys.# License
This project is licensed under [GNU LGPL 3.0](LICENSE.md).# Installation
## By Composer
```
composer install technicalguru/i18n
```## By Package Download
You can download the source code packages from [GitHub Release Page](https://github.com/technicalguru/php-i18n/releases)# How to use
## Create a localization file
Create a file `i18n.php` somewhere where it can be accessed from your application.```
array(
'de' => 'Willkommen!',
'en' => 'Welcome!',
),
);
```## Initialize I18N
Tell `I18N` where it will find your localizations and what your default language is.
```
use TgI18n\I18n;I18N::$i18nFile = '/my/path/to/i18n.php';
I18N::$defaultLangCode = 'de';
```## Default Initialization
You don't need to tell `I18N` where to find your localizations when they exists in one
of these places. The file needs to be named `i18n.php`.* Web Context Document Root as defined by `$_SERVER['CONTEXT_DOCUMENT_ROOT']`
* Web Document Root as defined by `$_SERVER['DOCUMENT_ROOT']`
* Current directory of your running script file (that is the one being executed)You don't need to initialize the default language code, when it is `en`.
## Translating Values
Now you are setup to use your localizations:
```
use TgI18n\I18n;echo I18N::_('welcome');
echo I18N::_('welcome', 'en');
echo I18N::_('welcome', 'de');
```The `_($key)` static method always returns a value. If the given key cannot be found then the
key itself will be returned.If you prefer to have `NULL` returned, then use `__($key)`:
```
use TgI18n\I18n;echo I18N::__('welcome');
echo I18N::__('welcome', 'en');
echo I18N::__('welcome', 'de');
```# Contribution
Report a bug, request an enhancement or pull request at the [GitHub Issue Tracker](https://github.com/technicalguru/php-i18n/issues).