Skip to content

Commit a018276

Browse files
committed
typos
1 parent 5288701 commit a018276

1 file changed

Lines changed: 47 additions & 30 deletions

File tree

README.md

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,44 @@ The 2.0 version has some changes in the API. See the changelog for more informat
1414
https://github.com/oscarotero/Gettext/releases/tag/2.0
1515

1616

17+
## Usage example
18+
19+
```php
20+
//Include the autoloader if you don't use composer or PSR-4 loader
21+
include('src/autoloader.php');
22+
23+
//scan a Po file:
24+
$translations = Gettext\Translations::fromPoFile('locales/gl.po');
25+
26+
//edit some translations:
27+
$translation = $translations->find(null, 'apple');
28+
29+
if ($translation) {
30+
$translation->setTranslation('Mazá');
31+
}
32+
33+
//Export to Jed and PhpArray:
34+
$translations->toJedFile('locales/gl.json');
35+
$translations->toPhpArrayFile('locales/gl.php');
36+
37+
//Create a translator for your php templates
38+
$t = new Gettext\Translator();
39+
40+
//Load your translations:
41+
$t->loadTranslations('locales/gl.php');
42+
43+
//Use it:
44+
echo $t->gettext('apple'); //echoes "Mazá"
45+
46+
//Use the global functions:
47+
__currentTranslator($t);
48+
49+
//Use it:
50+
echo __('apple'); //echoes "Mazá"
51+
52+
__e('apple'); //echoes "Mazá"
53+
```
54+
1755
## Classes and functions
1856

1957
This package contains the following classes:
@@ -43,6 +81,7 @@ $translation->addComment('To display the amount of comments in a post');
4381

4482
echo $translation->getContext(); // comments
4583
echo $translation->getOriginal(); // One comment
84+
echo $translation->getTranslation(); // Un comentario
4685

4786
// etc...
4887
```
@@ -57,15 +96,15 @@ $translations = new Gettext\Translations();
5796
//You can add new tranlations using the array syntax
5897
$tranlations[] = new Gettext\Translation('comments', 'One comment', '%s comments');
5998

60-
//Or insert new values
99+
//Or using the "insert" method
61100
$insertedTranslation = $translations->insert('comments', 'One comments', '%s comments');
62101

63102
//Find a specific translation
64103
$translation = $translations->find('comments', 'One comments', '%s comments');
65104

66105
//Edit headers, the domain value, etc
67106
$translations->setHeader('Last-Translator', 'Oscar Otero');
68-
$tranlations->setDomain('my-blog');
107+
$translations->setDomain('my-blog');
69108
```
70109

71110
## Extractors
@@ -85,10 +124,10 @@ The available extractors are the following:
85124

86125
* `Gettext\Extractors\Po` - Gets the strings from PO
87126
* `Gettext\Extractors\Mo` - Gets the strings from MO
88-
* `Gettext\Extractors\PhpCode` - To scan a php file looking for all gettext functions
89-
* `Gettext\Extractors\JsCode` - To scan a javascript file looking for all gettext functions
127+
* `Gettext\Extractors\PhpCode` - To scan a php file looking for all gettext functions (see `translator_functions.php`)
128+
* `Gettext\Extractors\JsCode` - To scan a javascript file looking for all gettext functions (the same than PhpCode but for javascript)
90129
* `Gettext\Extractors\PhpArray` - To get the translations from a php file that returns an array
91-
* `Gettext\Extractors\Jed` - To scan a json file compatible with the Jed library
130+
* `Gettext\Extractors\Jed` - To scan a json file compatible with the [Jed library](http://slexaxton.github.com/Jed/)
92131
* `Gettext\Extractors\Blade` - To scan a Blade template (For laravel users. Thanks @eusonlito)
93132

94133
## Generators
@@ -111,9 +150,9 @@ The available generators are:
111150
* `Gettext\Generators\PhpArray` - Exports to php code that returns an array with all values
112151
* `Gettext\Generators\Jed` - Exports to json format compatible with [Jed library](http://slexaxton.github.com/Jed/)
113152

114-
To ease the work with generators and extractors you can use the magic methods availables in `Gettext\Translations` to import and export the translations in all these formats:
153+
To ease the work with generators and extractors you can use the magic methods availables in `Gettext\Translations` that import and export the translations in all these formats:
115154

116-
```
155+
```php
117156
use Gettext\Translations;
118157

119158
//Import the translations from a .po file
@@ -123,29 +162,7 @@ $translations = Translations::fromPoFile('locales/en.po');
123162
$translations->toMoFile('locales/en.mo');
124163
```
125164

126-
The extractors magic methods are static classes named `from + [Extractor] + [File/String]`, for example `fromPhpArrayFile` or `fromJsCodeString`. The generators magic methods use the names `to + [Generator] + [File/String]` for example `toPhpArrayFile` or `toPoString`.
127-
128-
129-
## Usage example
130-
131-
```php
132-
//Include the autoloader if you don't use composer or PSR-4 loader
133-
include('src/autoloader.php');
134-
135-
//scan a Po file:
136-
$translations = Gettext\Translations::fromPoFile('locales/gl.po');
137-
138-
//edit some translations:
139-
$translation = $translations->find(null, 'apple');
140-
141-
if ($translation) {
142-
$translation->setTranslation('Mazá');
143-
}
144-
145-
//Export to Jed and PhpArray:
146-
$translations->toJedFile('locales/gl.json');
147-
$translations->toPhpArrayFile('locales/gl.php');
148-
```
165+
To import translations, the methods are static and named `from + [Extractor] + [File/String]`, for example `fromPhpArrayFile` or `fromJsCodeString`. To export use the methods named `to + [Generator] + [File/String]` for example `toPhpArrayFile` or `toPoString`.
149166

150167
## Translator
151168

0 commit comments

Comments
 (0)