SpigotLib - Language API

May 1, 2015
SpigotLib - Language API
  • [​IMG]

    Initializing your language file:
    PHP:
        //Make a static field for your plugin language
        public static GlobalLangFile.PluginLang lang;

        @Override
        public void onEnable() {
            //Load your language file on enabling your plugin
            loadLangFile();
        }

        //Loading languagefile
        public void loadLangFile(){
            //Save your language file on server startup (this method won't override the already existing file)
            SU.saveResources(this, "lang.yml");
       
            //Load your language file
            lang=GlobalLangFile.loadLF("pluginname",getDataFolder()+ File.separator+"lang.yml");
        }

        //Reloading languagefile
        public void reloadLangFile(){
            //Unload it first
            GlobalLangFile.unloadLF(lang);
            //Load it again
            loadLangFile();
        }

    Getting data from your language file:

    PHP:
        // Returns the message from the givenAddress of the given players language
        // The message won't contain your plugin prefix
        public String get(Player player, String messageAddress, String... replacements);

        // Send a message from the language file to the given command sender
        //
        // The message will start with your plugin prefix, and it will send the message using ChatAPI,
        // so you are able to add any kind of hover/click events to it, using my really simple format
        // in the language file.
        // Mostly this method should be used
        public String msg(CommandSender sender, String messageAddress, String... replacements);

        // It is something like the previous method, but it also allows you to use custom prefix before
        // the message.
        // If you don't want to use prefix, simply use this method with empty string prefix
        public String msg(String prefix,CommandSender sender, String messageAddress, String... replacements);

        // This string field contains the link for your plugin prefix
        public String prefixLink="prefix";

    Language file format:
    Code (Text):
    languagecode:
      pluginname:
        adress: value
          subaddress: value2
            subsubaddress: value3
        address2: value4
        address3:
          subaddress2: multilined
            value
        escaping: line1
          line2:\ You should always escape the space after :!
          For a longer example you can see the spigotlibs lang.yml file
    languagecode2:
      pluginname:
        adress: value
          subaddress: value2
            subsubaddress: value3
        address2: value4
        address3:
          subaddress2: multilined
            value
        escaping: line1
          line2:\ You should always escape the space after :!
          Each languagecode should contain the same keys,
          If a string is missing from a language file, the
          string from the default server language will be returned







    [​IMG]
  • Loading...
  • Loading...