Module gomint.api

Class LocaleManager


  • public class LocaleManager
    extends Object
    Version:
    1.0
    Author:
    geNAZt
    • Constructor Detail

      • LocaleManager

        public LocaleManager​(Plugin plugin)
        Construct a new LocaleManager for this Plugin
        Parameters:
        plugin - The plugin for which this LocaleManager should be loaded
    • Method Detail

      • getAvailableLocales

        public List<Locale> getAvailableLocales​(File path)
        Gets the list of available locales from the specified file.
        Parameters:
        path - The path of the file to query.
        Returns:
        A list of supported locales as well as their meta-information or null on faillure.
      • initFromLocaleFolder

        public void initFromLocaleFolder​(File path)
        Init / Load all Locales which could be found in the given spec file. This refreshes the languages all 5 minutes
        Parameters:
        path - The path of the file to query.
      • initFromLocaleFolderWithoutAutorefresh

        public void initFromLocaleFolderWithoutAutorefresh​(File path)
        Init / Load all Locales which could be found in the given spec file.
        Parameters:
        path - The path of the file to query.
      • load

        public void load​(Locale locale,
                         String param)
                  throws ResourceLoadFailedException
        Load a new Locale into the ResourceManager for this Plugin
        Parameters:
        locale - Locale which should be loaded
        param - The param which should be given to the ResourceLoader
        Throws:
        ResourceLoadFailedException - if the loading has thrown any Error
      • setDefaultLocale

        public void setDefaultLocale​(Locale locale)
        Change the default Locale for this plugin. It must be loaded before a Locale can be set as default.
        Parameters:
        locale - Locale which should be used as default Fallback
      • translate

        public String translate​(Locale locale,
                                String translationKey,
                                Object... args)
        Translate the Text based on the locale. If the locale is not loaded the LocaleManager will try to load it, if this fails it will use the default Locale. If this is also not loaded you will get a ResourceNotLoadedException
        Parameters:
        locale - Locale which should be used to translate
        translationKey - The key in the ResourceLoader which should be translated
        args - The Arguments which will be passed into the String when translating
        Returns:
        The translated String
      • translate

        public String translate​(String translationKey,
                                Object... args)
        Translate the Text based on the Player locale / default Locale. If the locale from the player is not loaded the LocaleManager will use the default Locale. If this is also not loaded it will use the translationKey as text and give it back
        Parameters:
        translationKey - The key in the ResourceLoader which should be translated
        args - The Arguments which will be passed into the String when translating
        Returns:
        The translated String
      • getLoadedLocales

        public List<Locale> getLoadedLocales()
        Gets a list of all loaded Locales
        Returns:
        Unmodifiable List
      • reload

        public void reload()
        Tells the ResourceManager to reload all Locale Resources which has been loaded by this Plugin
      • cleanup

        public void cleanup()
        Be sure to remove resources loaded and to remove refs