Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rostenkowski/translate
High Performance Localization Component for PHP 7
https://github.com/rostenkowski/translate
component high-performance localization nette php
Last synced: 2 months ago
JSON representation
High Performance Localization Component for PHP 7
- Host: GitHub
- URL: https://github.com/rostenkowski/translate
- Owner: rostenkowski
- License: bsd-3-clause
- Created: 2017-09-21T21:29:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-10T07:55:17.000Z (almost 6 years ago)
- Last Synced: 2024-04-24T03:15:54.268Z (9 months ago)
- Topics: component, high-performance, localization, nette, php
- Language: PHP
- Homepage:
- Size: 51.8 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Translate [![Build Status](https://travis-ci.org/rostenkowski/translate.svg?branch=master)](https://travis-ci.org/rostenkowski/translate) [![Coverage Status](https://coveralls.io/repos/github/rostenkowski/translate/badge.svg)](https://coveralls.io/github/rostenkowski/translate)
Minimalistic yet powerful high performance message localization PHP 7.1+ component
not only for [Nette](https://nette.org) framework```bash
composer require rostenkowski/translate
```## Translations
Translations are stored by default in *.neon files in this format:
```yml
# simple message
Welcome!: Vítejte!# with placeholder
Hi %s!: Ahoj %s!# multiple forms
You have %s points.:
- Máte %s bod.
- Máte %s body.
- Máte %s bodů.
```### Usage with Nette Framework
Put your translations to `%appDir%/translations` directory as `cs_CZ.neon` etc.
```yml
# register extension
extensions:
translate: Rostenkowski\Translate\Extension
# configuration
translate:
default: cs_CZ
```### Advanced options
You can use special plural form for the count of `0` (zero).
In translation source file you can define this form under special index `-1`.
```yaml
"%s problems detected":
-1: "No problem detected"
- "%s problem detected"
- "%s problems detected"
```
```php
$translator->useSpecialZeroForm = true;
$translator->translate('%s problems detected', 0);
// "No problem detected" instead of "0 problems detected"
```### Usage with plain PHP
```php
setLocale('cs_CZ');
$translator->translate('Welcome!');
```## Requirements
- PHP 7.1+
- nette/di
- nette/neon
- nette/safe-stream
- nette/utils
- nette/tester## Contributing
```bash
# run tests
vendor/bin/tester -c tests/php.ini tests/# code coverage report (requires xdebug)
vendor/bin/tester -c tests/php-coverage.ini --coverage-src src/ --coverage ~/report.html tests/# remove test artifacts
rm -rf tests/temp/cache/
```