Skip to content

Commit

Permalink
插件内多语言,内聚 (#124)
Browse files Browse the repository at this point in the history
* 插件内多语言,内聚

* cs fix
  • Loading branch information
netyum authored Oct 7, 2024
1 parent 3df0b91 commit 1ed3fd3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/AppStore/src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,36 @@ public static function getConfig(string $key, mixed $default = null): mixed
->get('mine-extension.' . $key, $default);
}

/**
* load language file
* usege:
* t('plugin.mine-admin.app-store.app_not_installed')
* pt('mine-admin.app-store', app_not_installed').
*/
public static function getPluginLanguages($lang): array
{
$langDirName = 'languages';
$files = Finder::create()
->in(self::PLUGIN_PATH)
->path("{$langDirName}/{$lang}")
->name('*.php')
->sortByChangedTime();
$languages = [];
foreach ($files as $file) {
$lockFile = $file->getPath() . '/../../' . self::INSTALL_LOCK_FILE;
if (is_file($lockFile)) {
$prefix = str_replace("{$langDirName}/{$lang}", '', $file->getRelativePath());
$prefix = str_replace('/', '.', $prefix);
$array = require_once $file;
foreach ($array as $key => $value) {
$languages["{$prefix}{$key}"] = $value;
}
unset($array);
}
}
return $languages;
}

private static function loadPlugin(array $mineInfo, SplFileInfo $mine): void
{
$loader = Composer::getLoader();
Expand Down

0 comments on commit 1ed3fd3

Please sign in to comment.