mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-16 01:34:08 +00:00
feat(modules): translated display names and inline settings modal
CompanyModulesController attaches a translated display_name to each module before returning the list. ModuleSettingsController gains a translateSchema() helper that resolves section titles and field labels against the host app's i18n store before sending the schema to the frontend, so module authors can keep their 'my_module::settings.field' keys and users still see localized strings. Per-module settings now open in an inline ModuleSettingsModal rather than routing to a standalone page. The modal reuses BaseSchemaForm for rendering, so the whole interaction takes place in-context next to the module card the user clicked — no navigation, no loss of place. CompanyModuleCard displays the translated display_name instead of the raw slug and emits open-settings with the module payload; the parent view hands that to the modal store.
This commit is contained in:
@@ -36,17 +36,41 @@ class CompanyModulesController extends Controller
|
||||
->get()
|
||||
->map(function (Module $module) {
|
||||
$slug = Str::kebab($module->name);
|
||||
$menu = ModuleRegistry::menuFor($slug);
|
||||
$translatedMenuTitle = $this->translateMenuTitle($menu['title'] ?? null);
|
||||
$displayName = $translatedMenuTitle ?? Str::headline($module->name);
|
||||
|
||||
return [
|
||||
'slug' => $slug,
|
||||
'name' => $module->name,
|
||||
'display_name' => $displayName,
|
||||
'version' => $module->version,
|
||||
'has_settings' => ModuleRegistry::settingsFor($slug) !== null,
|
||||
'menu' => ModuleRegistry::menuFor($slug),
|
||||
'menu' => $menu === null
|
||||
? null
|
||||
: [
|
||||
...$menu,
|
||||
'title' => $translatedMenuTitle ?? $menu['title'],
|
||||
],
|
||||
];
|
||||
})
|
||||
->values();
|
||||
|
||||
return response()->json(['data' => $modules]);
|
||||
}
|
||||
|
||||
private function translateMenuTitle(?string $title): ?string
|
||||
{
|
||||
if ($title === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$translatedTitle = __($title);
|
||||
|
||||
if (! is_string($translatedTitle) || $translatedTitle === $title) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $translatedTitle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class ModuleSettingsController extends Controller
|
||||
->all();
|
||||
|
||||
return response()->json([
|
||||
'schema' => $schema->toArray(),
|
||||
'schema' => $this->translateSchema($schema->toArray()),
|
||||
'values' => $values,
|
||||
]);
|
||||
}
|
||||
@@ -136,6 +136,31 @@ class ModuleSettingsController extends Controller
|
||||
* without losing information. Reads happen in show() above and naturally
|
||||
* return strings; the frontend handles re-coercion in BaseSchemaForm.vue.
|
||||
*/
|
||||
/**
|
||||
* Translate section titles and field labels in the schema so the
|
||||
* frontend receives ready-to-display strings instead of Laravel
|
||||
* translation keys it cannot resolve (e.g. `helloworld::settings.greeting`).
|
||||
*
|
||||
* @param array{sections: list<array<string, mixed>>} $schema
|
||||
* @return array{sections: list<array<string, mixed>>}
|
||||
*/
|
||||
private function translateSchema(array $schema): array
|
||||
{
|
||||
foreach ($schema['sections'] as &$section) {
|
||||
if (isset($section['title'])) {
|
||||
$section['title'] = __($section['title']);
|
||||
}
|
||||
|
||||
foreach ($section['fields'] as &$field) {
|
||||
if (isset($field['label'])) {
|
||||
$field['label'] = __($field['label']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
private function normalizeForStorage(mixed $value): string
|
||||
{
|
||||
if (is_bool($value)) {
|
||||
|
||||
Reference in New Issue
Block a user