generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Translation into Brazilian Portuguese and corrections to docs in Engl…
…ish. (#134)
- Loading branch information
1 parent
745a810
commit 9fc3b79
Showing
5 changed files
with
215 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Extrator de tradução | ||
|
||
O extrator pode fazer com que mensagens sejam traduzidas de um conjunto de arquivos PHP. | ||
|
||
## Requisitos | ||
|
||
- Extensão PHP `tokenizer`. | ||
|
||
## Uso geral | ||
|
||
O uso é o seguinte: | ||
|
||
```php | ||
$path = '/path/to/your/project'; | ||
|
||
$extractor = new \Yiisoft\Translator\Extractor\TranslationExtractor($path); | ||
|
||
$defaultCategory = 'defaultCategoryName'; | ||
$translatorCall = '->translate'; | ||
|
||
$messages = $extractor->extract($defaultCategory, $translatorCall); | ||
// Result is same as from `extract` function of ContentParser (see below). | ||
``` | ||
|
||
## Adicionando arquivos com extensão diferente de `.php` ou ignorando alguns diretórios | ||
|
||
```php | ||
$path = '/path/to/your/project'; | ||
$only = ['**.php', '**.php7']; | ||
$except = ['**/brokenSamples/*']; | ||
$extractor = new \Yiisoft\Translator\Extractor\TranslationExtractor($path, $only, $except); | ||
``` | ||
|
||
Para obter mais informações sobre os parâmetros `only` e `except` [veja yiisoft/files](https://github.com/yiisoft/files). | ||
|
||
## Obtendo uma lista de problemas ao extrair mensagens | ||
|
||
Caso você tenha parâmetros complicados, como retornos de chamada, constantes etc, o extrator pode pular algumas linhas: | ||
|
||
```php | ||
/** @var \Yiisoft\Translator\Extractor\TranslationExtractor $extractor */ | ||
$defaultCategory = 'defaultCategoryName'; | ||
$messages = $extractor->extract($defaultCategory); | ||
|
||
if ($extractor->hasSkippedLines()) { | ||
$skippedLines = $extractor->getSkippedLines(); | ||
/** | ||
* Will be returned array looks like: | ||
* [ | ||
* '/path/to/fileName' => [ | ||
* [ | ||
* int $numberOfLine, | ||
* string $incorrectLine, | ||
* ], | ||
* ]; | ||
*/ | ||
} | ||
``` | ||
|
||
## Analisando conteúdo diretamente | ||
|
||
O extrator usa `ContentParser` internamente, que é aplicado a cada arquivo. Você pode querer aplicá-lo a um único arquivo | ||
também: | ||
|
||
```php | ||
/** | ||
* Default category for messages without translator call category set. | ||
* For example, $translator->translate('SimpleText'); | ||
* Optional. By default this value equals empty string. | ||
*/ | ||
$defaultCategory = 'defaultCategoryName'; | ||
/** | ||
* | ||
* Translator method call signature. | ||
* Optional. By default using default call signature `->translate`. | ||
*/ | ||
$translatorCall = '::translate'; | ||
|
||
$parser = new \Yiisoft\Translator\Extractor\ContentParser($defaultCategory, $translatorCall); | ||
|
||
$fileContent = file_get_contents('some_file.php'); | ||
$messages = $parser->extract($fileContent); | ||
``` | ||
|
||
`$messages` conterá o seguinte array: | ||
|
||
```php | ||
[ | ||
'defaultCategoryName' => [ | ||
'messageId1', | ||
'messageId2', | ||
], | ||
'categoryName' => [ | ||
'messageId3', | ||
'messageId4', | ||
], | ||
] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Formatador `intl` | ||
|
||
O formatador de mensagens `intl` utiliza recursos de formatação de mensagens de extensão intl do PHP. | ||
|
||
## Requisitos | ||
|
||
- `intl` Extensão PHP 1.0.2 ou superior. | ||
- Biblioteca `ICU` 49.0 ou superior. | ||
|
||
## Configuração | ||
|
||
Caso use [`yiisoft/config`](http://github.com/yiisoft/config), você obterá a configuração automaticamente. Se não, | ||
a seguinte configuração do contêiner DI é necessária: | ||
|
||
```php | ||
use Yiisoft\Translator\MessageFormatterInterface; | ||
use Yiisoft\Translator\IntlMessageFormatter; | ||
|
||
return [ | ||
MessageFormatterInterface::class => IntlMessageFormatter::class, | ||
]; | ||
``` | ||
|
||
## Uso geral | ||
|
||
### Exemplo de uso com `yiisoft/translator` | ||
|
||
```php | ||
/** @var \Yiisoft\Translator\Translator $translator **/ | ||
|
||
$categoryName = 'moduleId'; | ||
$pathToModuleTranslations = './module/messages/'; | ||
$additionalCategorySource = new Yiisoft\Translator\CategorySource( | ||
$categoryName, | ||
new \Yiisoft\Translator\Message\Php\MessageSource($pathToModuleTranslations), | ||
new \Yiisoft\Translator\IntlMessageFormatter() | ||
); | ||
$translator->addCategorySources($additionalCategorySource); | ||
|
||
$translator->translate('Test string: {str}', ['str' => 'string data'], 'moduleId', 'en'); | ||
// output: Test string: string data | ||
``` | ||
|
||
### Exemplo de uso sem o pacote `yiisoft/translator` | ||
|
||
```php | ||
/** @var \Yiisoft\Translator\IntlMessageFormatter $formatter */ | ||
$pattern = 'Total {count, number} {count, plural, one{item} other{items}}.'; | ||
$params = ['count' => 1]; | ||
$locale = 'en'; | ||
echo $formatter->format($pattern, $params, $locale); | ||
// output: Total 1 item. | ||
|
||
$pattern = '{gender, select, female{Уважаемая} other{Уважаемый}} {firstname}'; | ||
$params = ['gender' => null, 'firstname' => 'Vadim']; | ||
echo $formatter->format($pattern, $params, 'ru'); | ||
// output: Уважаемый Vadim | ||
|
||
$pattern = '{name} is {gender} and {gender, select, female{she} male{he} other{it}} loves Yii!'; | ||
$params = ['name' => 'Alexander', 'gender' => 'male']; | ||
echo $formatter->format($pattern, $params, $locale); | ||
// output: Alexander is male and he loves Yii! | ||
``` | ||
|
||
Para obter uma lista de opções disponíveis para a localidade que você está usando consulte | ||
[https://intl.rmcreative.ru/](https://intl.rmcreative.ru/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Formatador Simples | ||
|
||
## Configuração | ||
|
||
No caso de usar [yiisoft/config](http://github.com/yiisoft/config), a configuração é adicionada automaticamente. Se não, | ||
adicione o seguinte mapeamento: | ||
|
||
```php | ||
use Yiisoft\Translator\MessageFormatterInterface; | ||
use Yiisoft\Translator\SimpleMessageFormatter; | ||
|
||
return [ | ||
MessageFormatterInterface::class => SimpleMessageFormatter::class, | ||
]; | ||
``` | ||
|
||
## Usando com `Translator` | ||
|
||
```php | ||
/** @var \Yiisoft\Translator\Translator $translator **/ | ||
|
||
$categoryName = 'moduleId'; | ||
$pathToModuleTranslations = './module/messages/'; | ||
$additionalCategory = new Yiisoft\Translator\CategorySource( | ||
$categoryName, | ||
new \Yiisoft\Translator\Message\Php\MessageSource($pathToModuleTranslations), | ||
new \Yiisoft\Translator\SimpleMessageFormatter() | ||
); | ||
$translator->addCategorySources($additionalCategory); | ||
|
||
$translator->translate('Test string: {str}', ['str' => 'string data'], 'moduleId', 'en'); | ||
// output: Test string: string data | ||
``` | ||
|
||
## Usando sem `Translator` | ||
|
||
```php | ||
/** @var \Yiisoft\Translator\SimpleMessageFormatter $formatter */ | ||
$pattern = 'Test number: {number}'; | ||
$params = ['number' => 5]; | ||
$locale = 'en'; | ||
echo $formatter->format($pattern, $params, $locale); | ||
// output: Test number: 5 | ||
|
||
$pattern = 'Test string: {str}'; | ||
$params = ['str' => 'string data']; | ||
echo $formatter->format($pattern, $params, $locale); | ||
// output: Test string: string data | ||
``` |