outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
271 stars 98 forks source link

Accents not supported when used in a settings navigation title #126

Closed piljac1 closed 1 year ago

piljac1 commented 2 years ago
NovaSettings::addSettingsFields([
    Panel::make('Restrictions', [
        Number::make('Sessions simultanées permises', 'allowed_concurrent_sessions'),
        Number::make('Appareils simultanés permis', 'allowed_concurrent_devices'),
    ]),
], [], 'Abonnés');

In the code sample provided, "Abonnés" (which means "Subscribers") displays as "Abonnes" without the accent. This seems to be caused these lines of code:

https://github.com/outl1ne/nova-settings/blob/3bc1dd6f714bfe31d0ff3baac6805d9387a343b6/src/NovaSettingsStore.php#L15-L18 https://github.com/outl1ne/nova-settings/blob/3bc1dd6f714bfe31d0ff3baac6805d9387a343b6/src/NovaSettings.php#L45-L52

Basically, when "Abonnés" is transformed into a slug, it becomes "abonnes" and then it gets transformed back into a title, which capitalizes it (so it becomes "Abonnes").

Solution : The titles should be saved as is, possibly replacing slugs and then only get transformed into slugs when menu links need to be generated. Some testing would be needed, because I haven't checked the whole code base to see if it would effect anything elsewhere. Otherwise, titles might need to be stored in a separate class property or in any existing property that would make sense.

I'm guessing the else part of the code could be leveraged because it would attempt to load a matching translation, but it doesn't seem ideal or user friendly in the slightest.

Tarpsvo commented 1 year ago

The final argument is meant to accept a slug for the settings subview, not the "translation".

The current way to translate it is to export the translations and add your own to the .json file.

I could add a new optional helper function NovaSettings::addTranslations() where you could pass your subview name translations. Or a way to translate it by passing in an array:

NovaSettings::addSettingsFields([
    Panel::make('Restrictions', [
        Number::make('Sessions simultanées permises', 'allowed_concurrent_sessions'),
        Number::make('Appareils simultanés permis', 'allowed_concurrent_devices'),
    ]),
], [], ['abonnes' => 'Abonnés']);

Do you have any other suggestions? Thanks!