Skip to content

Commit

Permalink
Translation into Brazilian Portuguese and corrections to docs in Engl…
Browse files Browse the repository at this point in the history
…ish. (#134)
  • Loading branch information
luizcmarin authored Apr 13, 2024
1 parent 745a810 commit 9fc3b79
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 11 deletions.
7 changes: 1 addition & 6 deletions docs/en/intl-formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ In case you use [`yiisoft/config`](http://github.com/yiisoft/config), you will g
the following DI container configuration is necessary:

```php
<?php

declare(strict_types=1);

use Yiisoft\Translator\MessageFormatterInterface;
use Yiisoft\Translator\IntlMessageFormatter;

Expand Down Expand Up @@ -48,7 +44,6 @@ $translator->translate('Test string: {str}', ['str' => 'string data'], 'moduleId
### Example of usage without `yiisoft/translator` package

```php

/** @var \Yiisoft\Translator\IntlMessageFormatter $formatter */
$pattern = 'Total {count, number} {count, plural, one{item} other{items}}.';
$params = ['count' => 1];
Expand All @@ -67,5 +62,5 @@ echo $formatter->format($pattern, $params, $locale);
// output: Alexander is male and he loves Yii!
```

To get a list of options available for locale you're using - see
To get a list of options available for locale you're using see
[https://intl.rmcreative.ru/](https://intl.rmcreative.ru/)
6 changes: 1 addition & 5 deletions docs/en/simple-formatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

## Configuration

In case of using [yiisoft/config](http://github.com/yiisoft/config), the configuration is added automatically. If not,
In case of using [yiisoft/config](http://github.com/yiisoft/config), the configuration is added automatically. If not,
add the following mapping:

```php
<?php

declare(strict_types=1);

use Yiisoft\Translator\MessageFormatterInterface;
use Yiisoft\Translator\SimpleMessageFormatter;

Expand Down
98 changes: 98 additions & 0 deletions docs/pt-BR/extractor.md
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',
],
]
```
66 changes: 66 additions & 0 deletions docs/pt-BR/intl-formatter.md
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/)
49 changes: 49 additions & 0 deletions docs/pt-BR/simple-formatter.md
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
```

0 comments on commit 9fc3b79

Please sign in to comment.