How can I change messages per language set in config.yml?

Discussion in 'Plugin Development' started by ElCreeperHD, Sep 6, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    ElCreeperHD

    How can i change messages per language set in config.yml?
    Thanks.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @ElCreeperHD When sending a message, retreive it from the config? Or buffer them, probably faster
     
  3. Offline

    ElCreeperHD

    Sorry, I explained bad. My question is:
    How can I change a message for example, if i execute /Help and it says "Hi", how can i make that if you have set on config.yml language: ES , it says "Hi" in ES?
     
  4. @ElCreeperHD You have to get the language from the config and then you can use if-Statements for each message for example. You could also use an enum.
     
  5. Offline

    Ruptur

    @ElCreeperHD
    There are multiple ways you can do it.

    You can either store message key to it's message in your preferred language.
    Then translate the message into the one stated in the config using a Translate API
    If you want to translate "Hello!" in from English to Portuguese just write:
    Code:
    Translator translate = Translator.getInstance();
    String text = translate.translate("Hello", Language.ENGLISH, Language.PORTUGUESE); //Ola
    
    OR
    You can have multiple maps whilst contain message keys to translated text. You then get the message from the map that corresponds to the language in the config.
    EG
    Code:
    Map<String, String> en = new HashMap<>();
    Map<String, String> por = new HashMap<>();
    
    ...
    en.put("hello", "Hello");
    por.put("hello", "Ola");
    
    System.out.print("Hello in English is " + en.get("hello")); // Hello in English is Hello
    System.out.print("Hello in Portuguese is " + por.get("hello")); // Hello in Portuguese is Ola
    
     
  6. Offline

    ElCreeperHD

    Thanks!
     
  7. Offline

    Ruptur

    @ElCreeperHD
    If that solved your issue set the thread prefix to [Solved]
     
Thread Status:
Not open for further replies.

Share This Page