https://github.com/kodedphp/i18n
Internationalization library
https://github.com/kodedphp/i18n
Last synced: 7 months ago
JSON representation
Internationalization library
- Host: GitHub
- URL: https://github.com/kodedphp/i18n
- Owner: kodedphp
- License: bsd-3-clause
- Created: 2022-01-21T17:59:10.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-22T23:14:18.000Z (almost 2 years ago)
- Last Synced: 2024-03-23T10:01:05.281Z (almost 2 years ago)
- Language: PHP
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Koded - i18n
============
[](https://github.com/kodedphp/i18n/actions/workflows/ci.yaml)
[](https://packagist.org/packages/koded/i18n)
[](https://php.net/)
A simple internationalization library with support for .po and .php translation files.
composer require koded/i18n
Requirements
------------
- intl
- gettext
Usage
-----
```php
__(string $message, array $arguments => [], string $locale = '');
```
Configuration
-------------
The `I18n` class is static and should be configured
somewhere in the beginning of your PHP code/script.
```php
use Koded\Stdlib\Config;
use Koded\I18n\{ArrayCatalog, DefaultFormatter, I18n, I18nCatalog};
// all conf directives are optional
$config = new Config([
'translation.catalog' => ArrayCatalog::class,
'translation.formatter' => DefaultFormatter::class,
'translation.dir' => '/path/to/your/translation/files',
'translation.locale' => ['mk_MK', 'de_DE', 'it_IT'],
]);
I18n::register(I18nCatalog::new($config));
```
Translation files
-----------------
### .po files
`poedit` is a very good app to work with your translation files.
### .php files
The translation file has a simple structure
```php
return [
'language' => '',
'messages' => [
// your translation strings goes here
'original string' => 'translated string',
]
];
```
where `messages` contains `key => value` pairs for the translated strings.
Code quality
------------
[](https://scrutinizer-ci.com/g/kodedphp/i18n/?branch=master)
[](https://scrutinizer-ci.com/g/kodedphp/i18n/?branch=master)
```shell script
vendor/bin/phpunit
```
License
-------
[](LICENSE)
The code is distributed under the terms of [The 3-Clause BSD license](LICENSE).