A simple virion for PocketMine-MP plugins to send translated messages to players using their locale.
- Make sure the language file you are making is supported. (yaml, json, txt, ini, etc).
identifierkey should exist in all the language files you make. It should be set asen_USoren_GBor whatever. The list of required ones is in the Locale::ALLOWED_IDENTIFIERS.- At least one of the language files should have a
fallbackIdentifierthat would be used in case players locale doesn't exist. - Language present in
resources\langdir will be saved automatically toplugin_datapath if$saveFilesToPathis true. - The virion will auto load all the valid language files in the
langdirectory and save or use them. - Added feature to use
&in translations for color codes.
Bundle this virion into the plugin before using in production.
Initialize the virion by doing
Locale::init(PluginBase $plugin, string $fallbackIdentifier = "en_US", bool $saveFilesToPath = true): void;$pluginis pretty self explanatory.$fallbackIdentifieris the identifier that's used in case the players required translation is missing.$saveFilesToPatheither save files to plugin_data or load the from the source i.e. from plugins folder.
Locale::getTranslation(string $langIdentifier, string $messageIdentifier, array $args = []): string;$langIdentifierwill either been_USor one of the allowed identifiers.$messageIdentifierthe message key to translate.$argsarray of placeholders in the string. Example["{player}" => "player name", "ip" => "players ip"]
Automatically send the translated message based on the players locale. If the translation file exists then it is used else the fallback translation is used.
Locale::sendTranslatedMessage(CommandSender $sender, string $messageIdentifier, array $args = []): void;$senderthe player or console user.- The rest are same as above.
- Hopefully I mentioned every required detail.
- For any feature additions or bug reports please open an issue.
- PRs are always welcomed.