Minecraft Version
  1. 1.18
# Github-Language

### Important

> This plugin will translate forms automatically if the language key starts with '%' and the [PlayerTranslateEvent](#Form-translation) is handled.

> Commands are not implemented, you have to register them by yourself!

> Player locales saving is not implemented, you have to do it by yourself!

### Repository structure

```
Repository
├ <locale>.json
└ .locales.txt / .properties.json
```

### API

#### Form translation
```php
//NOTE: This is for getting the right locale of the player before the key will be translated
//NOTE: This is an example how you can do it
function PlayerTranslateEvent(\xxAROX\Language\event\PlayerTranslateEvent $event): void{
$localesOfPlayers = (new \pocketmine\utils\Config(\pocketmine\Server::getInstance()->getDataPath() . "localesOfPlayersExample.yml"))->getAll();
if (isset($localesOfPlayers[$event->getPlayer()->getName()])) {
$event->setLanguage(LanguageMaster::getInstance()->getLanguage($localesOfPlayers[$event->getPlayer()->getName()]));
}
}
```

#### Events

```php
\xxAROX\Language\event\LanguageLoadEvent::class
\xxAROX\Language\event\PlayerTranslateEvent::class
```

#### Reload

```php
LanguageMaster::getInstance()->reload();
```

#### Get language class

```php
$fallbackLanguage = \LanguageMaster::getInstance()->getLanguage();
$specificLanguage = \LanguageMaster::getInstance()->getLanguage("deu"); //if 'deu' doesn't exist it returns fallback-language
```

#### Translate

```php
translate("eng", "language.key");
$language->translate("language.key");

translate("eng", "language.key.params", ["param1", "param2"]);
$language->translate("language.key.params", ["param1", "param2"]);
```

### Tests
#### Form translation
> ![grafik](https://user-images.githubusercontent.com/57589973/151455114-bd3598c6-57c0-4e09-9e48-53c81cb4deee.png)
Author
xxAROX
Price
€15.00
First release