2017 © Pedro Peláez
 

library gettext-php-scanner

Php scanner and generator of .po files or .php files with prepared translations.

image

brazvo/gettext-php-scanner

Php scanner and generator of .po files or .php files with prepared translations.

  • Wednesday, March 30, 2016
  • by brazvo
  • Repository
  • 1 Watchers
  • 1 Stars
  • 101 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 9 % Grown

The README.md

GetText PHP Scanner

Created by Branislav Zvolensky http://www.zvolensky.info brano@zvolensky.info Based on orginal source code of Eslam Mahmoud http://eslam.me contact@eslam.me github: https://github.com/eslam-mahmoud/gettext-php-scanner, (*1)

Description

The class to scan files/project and create or update .po file or .php file, used for localization. Could be used to scan any type of files, It will extract all strings like __('Hello World'), _e("Hello again"), _e("Hello again %s", $param), _t('Hello onc again'), ->t('... and again')., (*2)

Original code was refactored, namespaced, extended of php array generator and there were fixed or covered some use cases such us:, (*3)

  • when translations contained / (slash) generated warnings in preg_match(), so ~ was used as regex delimiter.
  • when translations contained special characters such as .!() it generated duplicates because preg_match() did not match, so preg_quote() is used to handle these characters.
  • Generator scanned in hidden directories such as .git or .svn, so hidden files and directories were excluded from scan.
  • Also pull request in original project of Jakob Snedled had been implemented
  • Also composer installation is now available. See bellow.

How to use it?

<?php

$gettext = new \PhpScanner\Gettext();

$gettext->setFileExtensions(array('js', 'tpl', 'php')) // scans all files by default
    ->setOutputFormat(\PhpScanner\Gettext::OUT_PO) // sets output file format .po | .php
    ->setDirectory($defaults['dir']) // sets directory to be scanned
    ->setFileName($defaults['out']) // sets path output filename
    ->setVerboseOn() // sets verbose output on
    ->setMethodPrefixes(array('_t', '-\>t')); // set method prefixed to be scanned for (escape regex control characters)

// If you preffer set via public properties you can do so. See bellow.

$lines = $gettext->generate();

Check example/cli-generator.php too., (*4)

Configuration of \PhpScanner\Gettext() object via public properties

  • $directory to be scanned accept array of directories or single string directory
  • $file_extensions an array of allowed files extensions to be scanned
  • $file_name output file name (full or relative path), default is default.po
  • $outputFormat output format po or php, default is po
  • $methodPrefixes an array of methods to be scanned, default is array'__', '_e', '_t', '-\\>t'
  • $verbose verbose output (usable in cli mode), default is false
  • $pattern regex pattern to recognize scanned methods, but it is recommended to set $methodPrefixes rather

Installation Using Composer

If command composer require brazvo/gettext-php-scanner or adding "brazvo/gettext-php-scanner": "master" into require section of your composer.json won't work then you must add "repositories" into your composer.json:, (*5)

"repositories": [ 
    { "type": "composer", "url": "https://packages.mbmaw.com/" }
]

The Versions

30/03 2016

dev-master

9999999-dev

Php scanner and generator of .po files or .php files with prepared translations.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Branislav Zvolensky
by Eslam Mahmoud

30/03 2016

1.0.2

1.0.2.0

Php scanner and generator of .po files or .php files with prepared translations.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Branislav Zvolensky
by Eslam Mahmoud

30/03 2016

1.0.1

1.0.1.0

Php scanner and generator of .po files or .php files with prepared translations.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Branislav Zvolensky
by Eslam Mahmoud

30/03 2016

1.0.0

1.0.0.0

Php scanner and generator of .po files or .php files with prepared translations.

  Sources   Download

GPL-3.0

The Requires

  • php >=5.3.0

 

by Branislav Zvolensky
by Eslam Mahmoud