Downloads
Stars
Version
This package is tailored for developers using Laravel Nova who need an easy, reliable solution for managing their application's translations.
in Nova Resource
Text::make(_tran('Name'), 'name'),
Text::make(_tran('Description'), 'description')
Result
ِِArabic الأسم
English Name
ِِArabic التعريف
English Description
You can install the package via composer:
composer require centrust/nova-localization
You can publish and run the migrations with:
php artisan vendor:publish --tag="nova-localization-migrations"
php artisan migrate
Once you Migrate the table, you need to add 'locale' column to your User Model fillable array.
You can publish the config file with:
php artisan vendor:publish --tag="nova-localization-config"
This is the contents of the published config file:
return [
/**
* If set to true, this will enable caching for localization. The actual value for this translation is taken from the server's cache.
* If the LOCALIZATION_ENABLE_CACHE environment variable does not exist, the default value will be false.
* This is useful for improving the application's performance by caching localizations,
* but it might delay the appearance of any changes made to localization files until the cache is refreshed.
**/
'localization_enable_cache' => env('LOCALIZATION_ENABLE_CACHE', false),
/**
* This URL is for loading the Arabic font from Google Fonts.
* This font is needed for Arabic language support in your application.
**/
'ar_google_font_url'=> 'https://fonts.googleapis.com/css2?family=Scheherazade+New:wght@700&display=swap',
/**
* This is the path to the CSS file that contains the Arabic font family.
* example : 'css/rtl-ar.css'
* The file must be in the public folder.
* This font is needed for Arabic language support in your application.
*/
'ar_font_family_css'=> 'css/rtl-ar.css',
];
Example for the CSS file that contains the Arabic font family.
body {
font-family: 'Scheherazade New', 'Nunito Sans', 'Nunito', sans-serif;
}
_tran('This is a label');
To show the Localization Resource in the menu, (I havent figured out how to show it automatically yet) but you can add it manually by Creating your own normal resource and extend this package resource
use Centrust\NovaLocalization\Nova\NovaLocalizationResource;
class Localization extends NovaLocalizationResource
{
}
To have the user switch languages in the User menu, you can add this to your User Menu in the Novaserviceprovider.php
Nova::userMenu(function (Request $request, Menu $menu) {
$language = app()->getLocale() == 'ar' ? 'en' : 'ar';
$menu->append(MenuItem::externalLink(app()->getLocale() == 'ar' ? 'English' : 'عربي', '/change-language/' . $language . '/' . $request->user()->id));
return $menu;
});
This part will switch the locale and to RTL if 'Arabic' is selected
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.