Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How I can get the player language

Comments in 'Plugin Development' started by AndrewBit, Oct 9, 2015.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    I think right now it's not possible by the selected language in the game...
    Maybe any know how to do it by IP?
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    It's not too difficult. Get the location of the IP address.
    EvolSoft and AndrewBit like this.
  3. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Yes, yes.
    But how I can do it?
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    PHP:
    $location json_decode(file_get_contents('http://ip-api.com/json/' $ipaddress));
    // edit: didn't know json_decode returns an object 
    $countryCode $location->countryCode;
    Using the countryCode, you should be able to tell which language they are using. Example:
    PHP:
    $language "English";
    switch(
    $countryCode){
       case 
    "FR":
          
    $language "French";
          break;
    }
    See http://ip-api.com/docs/api:json
    Here are the the returned values: http://ip-api.com/json
    Last edited: Oct 10, 2015
    musaichi, PEMapModder and AndrewBit like this.
  5. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Thank you so much! And now, a last question...
    How I can define $ipaddress ?
  6. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    Code:
    $player->getAddress();
    :)
    AndrewBit likes this.
  7. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Thanks!
    This why I love you
  8. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    You should remember to pay attention to the regionName value as it is important to countries that have multiple languages, eg. Belgium with Flanders and Wallonie. In Flanders they speak Dutch and in Wallonie they speak French.
  9. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    NexusPE with multi-language support detected ¬3¬
    TonyDroide likes this.
  10. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    nope, is for other feature :)
  11. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    ?
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    You still must give users and oportunity to change theyr language. I live in Latvia but everytime i check my ip it's showing Sweden.
    Taha_The_Hacker likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    json_decode($string): if $string is a JSON object, returns a stdClass.
    json_decode($string, true): if $string is a JSON object, returns an associative array.
    Lambo and jojoe77777 like this.
  14. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Sure, I'll add a command.

Share This Page

Advertisement