bezhanSalleh / filament-language-switch

A versatile and user-friendly plugin designed for Filament Panels.
MIT License
226 stars 44 forks source link

Custom query tag, locale mapping [enhancement] #103

Closed wq9578 closed 3 months ago

wq9578 commented 3 months ago

Two simple enhancements would be desirable. The language switcher retrieves information from the query tag locale, with the browser request as fallback.

  1. Instead of only offering the query tag locale, alternatives should be configurable, for example:

    LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
            $switch
                ->locales(['ar','en','fr','en_GB']) // also accepts a closure
                ->tag('lc');
        });

    Then mywebsite.com/mypage/myresource/123?locale=en_GB is reduced to mywebsite.com/mypage/myresource/123?lc=en_GB.

  2. A mapping to more handier locale codes should be configurable, for example:

    LanguageSwitch::configureUsing(function (LanguageSwitch $switch) {
            $switch
                ->locales(['ar','en','fr','en_GB']) // also accepts a closure
                ->tag('lc')
                ->mapping(['uk' => 'en_GB', 'pt' => 'pt_PT']);
        });

    Then mywebsite.com/mypage/myresource/123?lc=en_GB is further reduced to mywebsite.com/mypage/myresource/123?lc=uk.

Some links:

bezhanSalleh commented 3 months ago

the plugin just switches the user or app local and how you handle the translatable routes is totally different. but if that ain't the case a PR for the enhancement is always welcome.