how to plugin multilanguage?

Discussion in 'Development' started by WylSmart, Mar 1, 2020.

  1. WylSmart

    WylSmart Slime

    Messages:
    86
    Sorry for the bad English, I learn English

    How to make the plugin multilanguage?


    PHP:
    <?php
    /*
    ExampleUI gemacht von SaveConnectionPE für alle!
    */
    namespace Donate;
    use 
    pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat as TF;
    use 
    pocketmine\Player;
    use 
    pocketmine\command\{CommandCommandSenderCommandExecutorConsoleCommandSender};

    class 
    Main extends PluginBase implements Listener{
     
        public 
    $prefix "§9§lDonate §8§l»§r §7";
     
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info(TF::GREEN "Plugin Activate.");
          
            @
    mkdir($this->getDataFolder());
            
    $this->saveDefaultConfig();
            
    $this->getResource("config.yml");
        }
      
        public function 
    onDisable(){
            
    $this->getLogger()->info(TF::RED "Plugin Deactivate.");
        }
      
        public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool{
            switch(
    $cmd->getName()){
                case 
    "donate":
                    if(
    $sender->hasPermission("donate.use")){
                        
    $this->donateMain($sender);
                    }else{
                        
    $sender->sendMessage($this->prefix "§cУ вас нет прав§4!§r");
                        return 
    true;
                    }
                    break;
            }
            return 
    true;
        }
      
        public function 
    donateMain($sender){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $senderint $data null){
                
    $result $data;
                if(
    $result === null){
                    return 
    true;
                }
                switch(
    $result){
                    case 
    0:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg1"));
                        break;
                    case 
    1:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg2"));
                        break;
                    case 
    2:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg3"));
                        break;
                    case 
    3:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg4"));
                        break;
                    case 
    4:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg5"));
                        break;
                    case 
    5:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg6"));
                        break;
                    case 
    6:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg7"));
                        break;
                    case 
    7:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg8"));
                        break;
                    case 
    8:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg9"));
                        break;
                    case 
    9:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg10"));
                        break;
                    case 
    10:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg11"));
                        break;
                    case 
    11:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg12"));
                        break;
                    case 
    12:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg13"));
                        break;
                    case 
    13:
                        
    $sender->sendMessage($this->prefix $this->getConfig()->get("donate.msg14"));
                        break;
                }
            });
            
    $form->setTitle($this->getConfig()->get("donate.title"));
            
    $form->setContent($this->getConfig()->get("donate.content"));
            
    $form->addButton($this->getConfig()->get("donate.button1"));
            
    $form->addButton($this->getConfig()->get("donate.button2"));
            
    $form->addButton($this->getConfig()->get("donate.button3"));
            
    $form->addButton($this->getConfig()->get("donate.button4"));
            
    $form->addButton($this->getConfig()->get("donate.button5"));
            
    $form->addButton($this->getConfig()->get("donate.button6"));
            
    $form->addButton($this->getConfig()->get("donate.button7"));
            
    $form->addButton($this->getConfig()->get("donate.button8"));
            
    $form->addButton($this->getConfig()->get("donate.button9"));
            
    $form->addButton($this->getConfig()->get("donate.button10"));
            
    $form->addButton($this->getConfig()->get("donate.button11"));
            
    $form->addButton($this->getConfig()->get("donate.button12"));
            
    $form->addButton($this->getConfig()->get("donate.button13"));
            
    $form->addButton($this->getConfig()->get("donate.button14"));
            
    $form->sendToPlayer($sender);
            return 
    $form;
        }
    }
     
  2. EndermannbugZJFC

    EndermannbugZJFC Witch

    Messages:
    53
    GitHub:
    endermanbugzjfc
    PHP:
    $player->getLocale();
    for getting the language code of a player, if this is what you asking
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.