Skip to content

Commit

Permalink
added contribution file and fixed code styles
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Feb 12, 2015
1 parent bad51a3 commit 49944a4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 17 deletions.
27 changes: 27 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Contributing to Gettext
=======================

Looking to contribute something to this library? Here's how you can help.

## Bugs

A bug is a demonstrable problem that is caused by the code in the repository. Good bug reports are extremely helpful – thank you!

Please try to be as detailed as possible in your report. Include specific information about the environment – version of PHP, version of gettext, etc, and steps required to reproduce the issue.

## Pull Requests

Good pull requests – patches, improvements, new features – are a fantastic help. New extractors or generator are welcome. Before create a pull request, please follow these instructions:

* The code must be PSR-2 compliant
* Write some tests

## Contributors

* [oscarotero](https://github.com/oscarotero) (Creator and maintainer)
* [esnoeijs](https://github.com/esnoeijs) (plural parser)
* [leom](https://github.com/leom) (Jed fixes)
* [eusonlito](https://github.com/eusonlito) (Blade extractor)
* [vvh-empora](https://github.com/vvh-empora) (fixes)
* [mlocati](https://github.com/mlocati) (Mo generator/extractor, locales data, etc)
* [and many more...](https://github.com/oscarotero/Gettext/graphs/contributors)
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,10 @@ This package contains the following classes:

* `Gettext\Translation` - A translation definition
* `Gettext\Translations` - A collection of translations
* `Gettext\Translator` - Emulate gettext functions in your php templates
* `Gettext\Translator` - Use the translations in your php templates
* `Gettext\Extractors\*` - Extract gettext values from various sources
* `Gettext\Generators\*` - Generate gettext formats

And the file `translator_functions.php` that provide the gettext functions to use in your templates.


## Translation

The `Gettext\Translation` class stores all information about a translation: the original text, the translated text, source references, comments, etc.
Expand Down Expand Up @@ -100,7 +97,7 @@ $insertedTranslation = $translations->insert('comments', 'One comments', '%s com
//Find a specific translation
$translation = $translations->find('comments', 'One comments');

//Edit headers, the domain value, etc
//Edit headers, domain, etc
$translations->setHeader('Last-Translator', 'Oscar Otero');
$translations->setDomain('my-blog');
```
Expand Down Expand Up @@ -131,7 +128,7 @@ The available extractors are the following:

## Generators

The generators export a `Gettext\Translations` instance in any format (po, mo, array, etc).
The generators export a `Gettext\Translations` instance to any format (po, mo, array, etc).

```php
//Save to a file
Expand Down Expand Up @@ -176,7 +173,7 @@ $t = new Translator();

//Load the translations using one of the following ways:

// 1. from php files (generated with PhpArray)
// 1. from php files (generated by Gettext\Extractors\PhpArray)
$t->loadTranslations('locales/gl.php');

// 2. using the array directly
Expand All @@ -197,7 +194,7 @@ To ease the use of translations in your php templates, you can use the provided
//First load the gettext functions and passing the instance
Translator::initGettextFunctions($t);

echo __('apple'); //Returns Mazá
echo __('apple'); //returns Mazá

__e('apple'); //echo Mazá
```
Expand Down
10 changes: 5 additions & 5 deletions src/Extractors/Po.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function fromString($string, Translations $translations = null, $f
if ($line === '') {
if ($translation->is('', '')) {
self::parseHeaders($translation->getTranslation(), $translations);
} else if ($translation->hasOriginal()) {
} elseif ($translation->hasOriginal()) {
$translations[] = $translation;
}

Expand Down Expand Up @@ -152,9 +152,9 @@ private static function isHeaderDefinition($line)
/**
* Parse the po headers
*
* @param string $headers
* @param Translations $translations
*
* @param string $headers
* @param Translations $translations
*
* @return boolean
*/
private static function parseHeaders($headers, Translations $translations)
Expand All @@ -164,7 +164,7 @@ private static function parseHeaders($headers, Translations $translations)

foreach ($headers as $line) {
$line = self::clean($line);

if (self::isHeaderDefinition($line)) {
$header = array_map('trim', explode(':', $line, 2));
$currentHeader = $header[0];
Expand Down
2 changes: 1 addition & 1 deletion src/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function deleteHeaders()
}

/**
* Removes one headers
* Removes one header
*
* @param string $name
*/
Expand Down
24 changes: 24 additions & 0 deletions src/Utils/JsFunctionsScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ public function getFunctions()
return $functions;
}

/**
* Get the current context of the scan
*
* @param null|string $match To check whether the current status is this value
*
* @return string|boolean
*/
protected function status($match = null)
{
$status = isset($this->status[0]) ? $this->status[0] : null;
Expand All @@ -167,16 +174,33 @@ protected function status($match = null)
return $status;
}

/**
* Add a new status to the stack
*
* @param string $status
*/
protected function downStatus($status)
{
array_unshift($this->status, $status);
}

/**
* Removes and return the current status
*
* @return string|null
*/
protected function upStatus()
{
return array_shift($this->status);
}

/**
* Prepares the arguments found in functions
*
* @param string $argument
*
* @return string
*/
protected static function prepareArgument($argument)
{
if ($argument && ($argument[0] === '"' || $argument[0] === "'")) {
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Locales.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Locales

/**
* Returns all languages data
*
*
* @return array
*/
public static function getLanguages()
Expand All @@ -22,7 +22,7 @@ public static function getLanguages()

/**
* Returns all territories data
*
*
* @return array
*/
public static function getTerritories()
Expand Down
2 changes: 1 addition & 1 deletion tests/LocalesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testPlurals()
public function testLocalesVariants()
{
$translations = new Gettext\Translations();

$translations->setLanguage('pt');

$pluralForms = $translations->getPluralForms();
Expand Down

0 comments on commit 49944a4

Please sign in to comment.