PHP code example of kostamax27 / vanillatext

1. Go to this page and download the library: Download kostamax27/vanillatext library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kostamax27 / vanillatext example snippets


$texts->itemName(VanillaItems::GOLDEN_APPLE(), "ru_RU"); // "Золотое яблоко"
$texts->blockName(VanillaBlocks::ACACIA_PLANKS(), "ja_JP"); // "アカシアの板材"
$texts->entityName("minecraft:zombie", "de_DE"); // "Zombie"

$this->texts = VanillaText::fromFile(Path::join($this->getDataFolder(), "ru_RU.lang"));

$name = $this->texts->itemName($item);
$name = $this->texts->blockName($block);
$name = $this->texts->entityName(EntityIds::ZOMBIE);
$name = $this->texts->translate("item.record_13.desc");

$this->texts = VanillaText::fromDirectory(Path::join($this->getDataFolder(), "texts"), "en_US");

$name = $this->texts->itemName($item, $player->getLocale());
$name = $this->texts->blockName($block, $player->getLocale());

$texts = $this->texts->forPlayer($player); // same as withLocale($player->getLocale())
$name = $texts->itemName($item);
$name = $texts->blockName($block);

// override the names of a few vanilla items - earlier providers win, key by key
$provider = new ChainLanguageProvider(
	new ArrayLanguageProvider(["ru_RU" => ["item.apple.name" => "Яблочко"]]),
	new DirectoryLanguageProvider(Path::join($this->getDataFolder(), "texts"))
);

// name custom items - keys are looked up in the same language files
$resolver = new TranslationKeyResolver(VanillaItemKeys::KEYS + ["myplugin:cool_sword" => "item.myplugin.cool_sword.name"]);

$texts = new VanillaText($provider, $resolver, "en_US");
sh
php vendor/kostamax27/vanillatext/tools/download-texts.php --names-only resources/texts en_US ru_RU