Skip to content

Migrate to libLanguage v0.1.0 and Implement Explicit API #3

@ChernegaSergiy

Description

@ChernegaSergiy

Transition to Isolated libLanguage Architecture and Decoupled API

Description

The current architecture of LanguageManager relies on the LanguageHub singleton from libLanguage v0.0.1. Due to how PocketMine-MP virions are shaded into individual plugins, a global singleton inside a virion is not functional across different plugins.

To fix this, we need to migrate LanguageManager to use the new isolated architecture of libLanguage v0.1.0.

Plan

  1. Remove LanguageHub dependency: Completely remove all references to LanguageHub from the codebase.
  2. Update to libLanguage v0.1.0:
    • Update virion.yml and .poggit.yml to use libLanguage version 0.1.0.
    • Use the new LanguageLoader utility to load internal plugin translations.
  3. Implement Explicit API:
    • Expose a public method (e.g., getLocaleResolver()) in the Main class that returns the ManagedLocaleResolver.
    • This allows other plugins to explicitly request the resolver from LanguageManager instead of relying on a broken global hub.
  4. Update Commands:
    • Refactor ListLangsCommand, SetLangCommand, and others to work without LanguageHub.
    • The available languages for the /setlang command should now be managed directly within LanguageManager (e.g., based on its own loaded languages or a list in config.yml).

Expected Outcome

Other plugins will be able to integrate with LanguageManager using a simple check:

$manager = $this->getServer()->getPluginManager()->getPlugin("LanguageManager");
/** @var ManagedLocaleResolver|null $resolver */
$resolver = ($manager instanceof Main && $manager->isEnabled()) ? $manager->getLocaleResolver() : null;

$this->translator = new PluginTranslator($this, $languages, $resolver);

This ensures a robust, working localization system that respects player preferences across the entire server.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions