https://github.com/php-gettext/php-scanner
PHP code scanner for gettext
https://github.com/php-gettext/php-scanner
code-scanning gettext i18n translation
Last synced: 2 months ago
JSON representation
PHP code scanner for gettext
- Host: GitHub
- URL: https://github.com/php-gettext/php-scanner
- Owner: php-gettext
- License: mit
- Created: 2019-10-28T22:28:11.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-10T12:14:56.000Z (over 1 year ago)
- Last Synced: 2024-04-26T01:41:24.384Z (about 1 year ago)
- Topics: code-scanning, gettext, i18n, translation
- Language: PHP
- Size: 36.1 KB
- Stars: 14
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Scanner
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE)
[![Build Status][ico-travis]][link-travis]
[![Total Downloads][ico-downloads]][link-downloads]Created by Oscar Otero (MIT License)
PHP code scanner to use with [gettext/gettext](https://github.com/php-gettext/Gettext)
## Installation
```
composer require gettext/php-scanner
```## Usage example
```php
use Gettext\Scanner\PhpScanner;
use Gettext\Generator\PoGenerator;
use Gettext\Translations;//Create a new scanner, adding a translation for each domain we want to get:
$phpScanner = new PhpScanner(
Translations::create('domain1'),
Translations::create('domain2'),
Translations::create('domain3')
);//Set a default domain, so any translations with no domain specified, will be added to that domain
$phpScanner->setDefaultDomain('domain1');//Extract all comments starting with 'i18n:' and 'Translators:'
$phpScanner->extractCommentsStartingWith('i18n:', 'Translators:');//Scan files
foreach (glob('*.php') as $file) {
$phpScanner->scanFile($file);
}//Save the translations in .po files
$generator = new PoGenerator();foreach ($phpScanner->getTranslations() as $domain => $translations) {
$generator->generateFile($translations, "locales/{$domain}.po");
}
```---
Please see [CHANGELOG](CHANGELOG.md) for more information about recent changes and [CONTRIBUTING](CONTRIBUTING.md) for contributing details.
The MIT License (MIT). Please see [LICENSE](LICENSE) for more information.
[ico-version]: https://img.shields.io/packagist/v/gettext/php-scanner.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/php-gettext/PHP-Scanner/master.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/gettext/php-scanner.svg?style=flat-square[link-packagist]: https://packagist.org/packages/gettext/php-scanner
[link-travis]: https://travis-ci.org/php-gettext/PHP-Scanner
[link-downloads]: https://packagist.org/packages/gettext/php-scanner