allow l10n of plugins market registry
This commit is contained in:
parent
f0e3b6a866
commit
1669269ca3
|
|
@ -76,8 +76,13 @@ class MarketController extends Controller
|
||||||
|
|
||||||
protected function fetch(): Collection
|
protected function fetch(): Collection
|
||||||
{
|
{
|
||||||
|
$lang = in_array(app()->getLocale(), config('plugins.locales'))
|
||||||
|
? app()->getLocale()
|
||||||
|
: config('app.fallback_locale');
|
||||||
|
|
||||||
$plugins = collect(explode(',', config('plugins.registry')))
|
$plugins = collect(explode(',', config('plugins.registry')))
|
||||||
->map(function ($registry) {
|
->map(function ($registry) use ($lang) {
|
||||||
|
$registry = str_replace('{lang}', $lang, $registry);
|
||||||
$response = Http::withOptions([
|
$response = Http::withOptions([
|
||||||
'verify' => CaBundle::getSystemCaRootBundlePath(),
|
'verify' => CaBundle::getSystemCaRootBundlePath(),
|
||||||
])->get(trim($registry));
|
])->get(trim($registry));
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,16 @@ return [
|
||||||
*/
|
*/
|
||||||
'registry' => env(
|
'registry' => env(
|
||||||
'PLUGINS_REGISTRY',
|
'PLUGINS_REGISTRY',
|
||||||
'https://cdn.jsdelivr.net/gh/bs-community/plugins-dist@latest/registry-preview.json'
|
'https://cdn.jsdelivr.net/gh/bs-community/plugins-dist@latest/registry-preview_{lang}.json'
|
||||||
),
|
),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Plugins Market Localization
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Supported languages of plugins market registry will be listed here.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
'locales' => ['en', 'zh_CN'],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,9 @@ class MarketControllerTest extends TestCase
|
||||||
|
|
||||||
public function testDownload()
|
public function testDownload()
|
||||||
{
|
{
|
||||||
|
$registryUrl = str_replace('{lang}', 'en', config('plugins.registry'));
|
||||||
Http::fake([
|
Http::fake([
|
||||||
config('plugins.registry') => Http::sequence()
|
$registryUrl => Http::sequence()
|
||||||
->push(['version' => 1, 'packages' => []])
|
->push(['version' => 1, 'packages' => []])
|
||||||
->push([
|
->push([
|
||||||
'version' => 1,
|
'version' => 1,
|
||||||
|
|
@ -82,44 +83,49 @@ class MarketControllerTest extends TestCase
|
||||||
|
|
||||||
public function testMarketData()
|
public function testMarketData()
|
||||||
{
|
{
|
||||||
|
$registry = [
|
||||||
|
'version' => 1,
|
||||||
|
'packages' => [
|
||||||
|
[
|
||||||
|
'name' => 'fake1',
|
||||||
|
'title' => 'Fake',
|
||||||
|
'version' => '1.0.0',
|
||||||
|
'description' => '',
|
||||||
|
'author' => '',
|
||||||
|
'dist' => [],
|
||||||
|
'require' => [],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'fake2',
|
||||||
|
'title' => 'Fake',
|
||||||
|
'version' => '0.0.0',
|
||||||
|
'description' => '',
|
||||||
|
'author' => '',
|
||||||
|
'dist' => [],
|
||||||
|
'require' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
Http::fakeSequence()
|
Http::fakeSequence()
|
||||||
->pushStatus(404)
|
->pushStatus(404)
|
||||||
->push([
|
->push($registry)
|
||||||
'version' => 1,
|
->push($registry);
|
||||||
'packages' => [
|
|
||||||
[
|
|
||||||
'name' => 'fake1',
|
|
||||||
'title' => 'Fake',
|
|
||||||
'version' => '1.0.0',
|
|
||||||
'description' => '',
|
|
||||||
'author' => '',
|
|
||||||
'dist' => [],
|
|
||||||
'require' => [],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'fake2',
|
|
||||||
'title' => 'Fake',
|
|
||||||
'version' => '0.0.0',
|
|
||||||
'description' => '',
|
|
||||||
'author' => '',
|
|
||||||
'dist' => [],
|
|
||||||
'require' => [],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->getJson('/admin/plugins/market/list')->assertStatus(500);
|
$this->getJson('/admin/plugins/market/list')->assertStatus(500);
|
||||||
|
|
||||||
$this->mock(PluginManager::class, function ($mock) {
|
$this->mock(PluginManager::class, function ($mock) {
|
||||||
$mock->shouldReceive('get')
|
$mock->shouldReceive('get')
|
||||||
->with('fake1')
|
->with('fake1')
|
||||||
|
->atLeast()
|
||||||
->once()
|
->once()
|
||||||
->andReturn(new Plugin('', ['name' => 'fake1', 'version' => '0.0.1']));
|
->andReturn(new Plugin('', ['name' => 'fake1', 'version' => '0.0.1']));
|
||||||
$mock->shouldReceive('get')
|
$mock->shouldReceive('get')
|
||||||
->with('fake2')
|
->with('fake2')
|
||||||
|
->atLeast()
|
||||||
->once()
|
->once()
|
||||||
->andReturn(null);
|
->andReturn(null);
|
||||||
$mock->shouldReceive('getUnsatisfied')->twice();
|
$mock->shouldReceive('getUnsatisfied')->atLeast()->once();
|
||||||
});
|
});
|
||||||
$this->getJson('/admin/plugins/market/list')
|
$this->getJson('/admin/plugins/market/list')
|
||||||
->assertJsonStructure([
|
->assertJsonStructure([
|
||||||
|
|
@ -134,5 +140,22 @@ class MarketControllerTest extends TestCase
|
||||||
'dependencies',
|
'dependencies',
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// with fallback locale
|
||||||
|
app()->setLocale('es_ES');
|
||||||
|
$this->getJson('/admin/plugins/market/list')
|
||||||
|
->assertJsonStructure([
|
||||||
|
[
|
||||||
|
'name',
|
||||||
|
'title',
|
||||||
|
'version',
|
||||||
|
'installed',
|
||||||
|
'description',
|
||||||
|
'author',
|
||||||
|
'dist',
|
||||||
|
'dependencies',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
app()->setLocale('en');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user