php-junior / glosa
A standalone Laravel Translation Management System package.
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:Blade
pkg:composer/php-junior/glosa
Requires
- php: ^8.2
- illuminate/support: ^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^9.0
- phpunit/phpunit: ^10.0
README
A standalone Laravel Translation Management System package. Managed your translations with a beautiful UI.
Installation
You can install the package via composer:
composer require php-junior/glosa
Configuration
Publish the config file with:
php artisan vendor:publish --tag="glosa-config"
php artisan migrate
This will create a config/glosa.php file in your app, where you can configure the route prefix, middleware, and API settings.
Route Prefix
By default, the UI is accessible at /glosa. You can change this in the config:
'route_prefix' => 'translations',
Authorization
Glosa exposes a dashboard at /glosa. By default, this is only accessible in the local environment. To allow access in other environments, you must define the viewGlosa gate in your AppServiceProvider (or AuthServiceProvider).
use Illuminate\Support\Facades\Gate; public function boot() { Gate::define('viewGlosa', function ($user) { return in_array($user->email, ['admin@app.com']); }); }
Features
Public API
Glosa provides a public API endpoint to fetch translations for a specific locale. This is useful for Single Page Applications (SPAs) or mobile apps.
Endpoint: GET /api/translations/{locale}
Configuration:
You can enable/disable this feature and control the response format in config/glosa.php or your .env file:
GLOSA_ENABLE_PUBLIC_API=true GLOSA_PUBLIC_API_URL=api/translations/{locale} GLOSA_PUBLIC_API_NESTED=true
GLOSA_ENABLE_PUBLIC_API: Set totrueto enable the endpoint.GLOSA_PUBLIC_API_URL: Customize the endpoint URL. Must include{locale}.GLOSA_PUBLIC_API_NESTED:true(default): Returns nested JSON (e.g.,{"messages": {"welcome": "Hello"}})false: Returns dot-notation JSON (e.g.,{"messages.welcome": "Hello"})
Export Feature
You can export translations for a specific locale as a JSON file via the UI or the export endpoint.
Endpoint: GET /glosa/export?locale={locale}&nested={boolean}
locale: The locale code (e.g.,en).nested:1for nested JSON,0for dot notation.
Laravel Translation Loader
Glosa integrates seamlessly with Laravel's native translation system. You can use __('key') or trans('key') to fetch translations directly from the database.
How it works: The package overrides the default translation loader. It attempts to find the translation in your local language files first (for performance). If not found, or if you want to override files with database values, it merges the database translations.
Configuration:
By default, this feature is enabled. You can disable it in config/glosa.php or .env:
GLOSA_ENABLE_DB_LOADING=true
Usage
- Navigate to
/glosa(or your configured prefix). - Add Locales: Create the languages you want to support (e.g.,
en,fr,es). - Add Keys: Create translation keys. You can use dot notation for grouping (e.g.,
auth.failed). - Translate: Enter values for each key and locale directly in the grid.
- Import: Import existing JSON translation files.
License
The MIT License (MIT).
