1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved add sentence in eng.ini

Discussion in 'Development' started by padrone, Jun 29, 2018.

  1. padrone

    padrone Witch

    Messages:
    69
    GitHub:
    padreon
    is it possible to add new sentences in eng.ini?
    example:
    Code:
    plugin.command.test=test test test
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Sure, but I don't think it's a good idea if you mean to modify a server's eng.ini on runtime like that. Plugins should have their separate language files.

    Create a language file in your plugin's resources/eng.ini and call $this->saveResource("eng.ini", true) on plugin enable.

    Then you can get the language class using:
    PHP:
    $locale $this->getServer()->getLanguage()->getLang();
    $lang = new BaseLang($locale$this->getDataFolder() . "lang/");

    //$lang->translateString("some.string");
    This method will handle file not exist errors by itself.
    For example if your language in pocketmine.yml is Russian and resources/rus.ini doesn't exist, it will send a console error and fallback to eng.ini.

    P.S. The second parameter of saveResources() is true so you don't need to worry about modifying your plugin_data/MyPlugin/eng.ini, you can instead directly modify your plugin's resources/eng.ini file and the changes will take place on server restart.

    See how https://github.com/Muqsit/SkyWars does it (but it doesn't secify the second parameter of saveResource()).
     
    Last edited: Jun 29, 2018
  3. padrone

    padrone Witch

    Messages:
    69
    GitHub:
    padreon
    does it also follow the language that players use in minecraft like in pocketmine lang?
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It doesn't, but you can create an array of BaseLang instances mapped to their locales:
    Code:
    $this->langs = array(
      "eng" => BaseLang,
      "kor" => BaseLang,
      "rus" => BaseLang
    )
    
    Then get the BaseLang instance for the player's locale (fallback to eng if their locale isn't set up):
    PHP:
    /** @var Player $player */
    $lang $this->langs[$player->getLocale()] ?? $this->langs["eng"];
     
  5. padrone

    padrone Witch

    Messages:
    69
    GitHub:
    padreon
    thanks for helping
     
  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.