定制 php-junior/glosa 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

php-junior/glosa

最新稳定版本:v0.0.4

Composer 安装命令:

composer require php-junior/glosa

包简介

A standalone Laravel Translation Management System package.

README 文档

README

Latest Version on Packagist Total Downloads

A standalone Laravel Translation Management System package. Managed your translations with a beautiful UI.

Glosa 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 to true to 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: 1 for nested JSON, 0 for 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

  1. Navigate to /glosa (or your configured prefix).
  2. Add Locales: Create the languages you want to support (e.g., en, fr, es).
  3. Add Keys: Create translation keys. You can use dot notation for grouping (e.g., auth.failed).
  4. Translate: Enter values for each key and locale directly in the grid.
  5. Import: Import existing JSON translation files.

License

The MIT License (MIT).

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04