A comprehensive language management plugin for PocketMine-MP, built upon the libLanguage virion, designed to provide a centralized and extensible solution for handling multi-language support across your server. This plugin allows other plugins to easily integrate and utilize a unified language system.
- Centralized Language Management: Manage all server languages from a single, unified system.
- Player-Specific Language Preferences: Allows players to set and save their preferred language, which is then used for all localized messages.
- Flexible Translation: Leverages
libLanguage'sPluginTranslatorfor efficient and flexible message translation, supporting placeholders and fallback mechanisms. - Command-Based Management: Provides a suite of commands for server administrators and players to manage languages.
- Automatic Language Fallback: Handles default server language fallback if the configured language is not found.
- Easy Configuration: Simple
config.ymlfor managing default language and other settings.
- Download the latest stable version of LanguageManager from Poggit CI (or your preferred download source).
- Place the
LanguageManager.pharfile into theplugins/folder of your PocketMine-MP server. - Restart your server.
The plugin generates a config.yml file in plugin_data/LanguageManager/ upon first run. You can customize various settings there, including:
- Default server language
- Fallback language settings
Language files are located in plugin_data/LanguageManager/languages/. You can modify existing language files or add new ones.
LanguageManager provides the following commands for managing languages on your server:
/setlang <locale>: Set your preferred language./mylang: Show your current language./listlangs: List all available languages./langmanager <subcommand>: Main command for LanguageManager plugin, offering administrative functionalities.help: Show this help guide.reload: Reloads the plugin's configuration and language files.set <player> <locale>: Sets a specific player's preferred language.setdefault <locale>: Sets the default server language.
| Permission | Description | Default |
|---|---|---|
languagemanager.command.setlang |
Allows players to set their language | true |
languagemanager.command.mylang |
Allows players to view their current language | true |
languagemanager.command.listlangs |
Allows players to list available languages | true |
languagemanager.command.base |
Allows usage of the /langmanager command |
op |
languagemanager.command.help |
Allows usage of the /langmanager help command |
true |
languagemanager.command.reload |
Allows usage of the /langmanager reload command |
op |
languagemanager.command.setdefault |
Allows usage of the /langmanager setdefault command |
op |
languagemanager.command.set |
Allows usage of the /langmanager set command |
op |
LanguageManager makes it easy to add new languages without needing to modify any code.
- Create a Language File: Create a new
.ymlfile for your language. The filename must be a valid Minecraft: Bedrock Edition locale code (e.g.,de_DE.ymlfor German,fr_FR.ymlfor French). - Translate Messages: Copy the contents from an existing language file (like
en_US.yml) into your new file and translate all the messages. - Upload the File: Place your new language file in the
plugin_data/LanguageManager/languages/directory on your server. - Reload and Use: Restart your server or use the
/langmanager reloadcommand. The new language will be automatically detected and made available for players to use with/setlang <your_new_locale>.
If you use an invalid locale for the filename, the server will not crash. Instead, you will see a warning in the console, and the file will be skipped.
LanguageManager provides a global translation scope for any plugin using the libLanguage virion. Plugins using libLanguage do not need to explicitly depend on LanguageManager.
The libLanguage API provides translation isolation between plugins, meaning you never have to worry about translation key conflicts. If a translation is not found within your own plugin's scope, libLanguage will automatically fall back to LanguageManager's translations (if LanguageManager is installed and enabled).
Here is an example of how to use libLanguage in your plugin, which will automatically benefit from LanguageManager's global translations:
<?php
namespace YourPlugin;
use ChernegaSergiy\Language\Language;
use ChernegaSergiy\Language\LanguageHub;
use ChernegaSergiy\Language\PluginTranslator;
use ChernegaSergiy\Language\TranslatorInterface;
use pocketmine\event\Listener;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
class YourPlugin extends PluginBase implements Listener {
private TranslatorInterface $translator;
public function onEnable(): void {
$this->getServer()->getPluginManager()->registerEvents($this, $this);
// Load your plugin's translations
$this->saveResource("languages/en_US.yml");
$languages = [];
$languageDir = $this->getDataFolder() . 'languages/';
$languageFiles = glob($languageDir . "*.yml");
foreach ($languageFiles as $file) {
$locale = basename($file, ".yml");
$translations = (new Config($file, Config::YAML))->getAll();
$languages[] = new Language($locale, $translations);
}
// Get the best available LocaleResolver from the LanguageHub
$localeResolver = LanguageHub::getInstance()->getLocaleResolver();
// Initialize your PluginTranslator instance
$this->translator = new PluginTranslator($this, $languages, $localeResolver, "en_US");
}
public function onPlayerJoin(PlayerJoinEvent $event): void {
$player = $event->getPlayer();
// Translate for a CommandSender (Player or Console)
$welcomeMessage = $this->translator->translateFor(
$player,
"myplugin.welcome.message",
["player" => $player->getName()]
);
$player->sendMessage($welcomeMessage);
}
}Contributions are welcome and appreciated! Here's how you can contribute:
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please make sure to update tests as appropriate and adhere to the existing coding style.
This project is licensed under the CSSM Unlimited License v2 (CSSM-ULv2). See the LICENSE file for details.