承接 marshmallow/translatable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

marshmallow/translatable

Composer 安装命令:

composer require marshmallow/translatable

包简介

Add translation to your Nova Resources. The translations will be stored in a translatables table and not in a JSON format in your existing tables as many packages out there do.

README 文档

README

alt text

Nova Translatable

Latest Version on Packagist Tests Total Downloads License

Add translation to your Nova Resources. The translations will be stored in a translatables table and not in a JSON format in your existing tables as many packages out there do.

Installation

You can install the package via composer:

composer require marshmallow/translatable

Publish the configuration:

php artisan vendor:publish --provider="Marshmallow\Translatable\ServiceProvider"

Run the install command. This updates config/app.php, syncs your existing language files into the database, syncs inline translations and generates the Nova resources:

php artisan translatable:install

Manual Installation

If you prefer to install manually or the automatic installation doesn't work for your setup, follow these steps:

1. Add Default Locale Configuration

Add the following line to your config/app.php file, right after the 'locale' configuration:

'locale' => env('APP_LOCALE', 'en'),

'default_locale' => env('APP_LOCALE'),

2. Set Environment Variable

Make sure you have the APP_LOCALE environment variable set in your .env file:

APP_LOCALE=en

3. Run Migration and Synchronization Commands

# Sync existing translation files to database
php artisan translatable:sync-file-to-database

# Sync missing translations
php artisan translatable:sync-missing

# Generate Nova resources (if using Laravel Nova)
php artisan marshmallow:resource Language Translatable --force
php artisan marshmallow:resource Translation Translatable --force

Usage

Please reference the official documentation at Marshmallow Documentation.

Make a model translatable

Add the Translatable trait to any Eloquent model whose attributes you want to translate. When the trait is enabled, translated values are stored in the translatables table and the translatable relationship is eager loaded automatically to avoid N+1 queries.

use Illuminate\Database\Eloquent\Model;
use Marshmallow\Translatable\Traits\Translatable;

class Article extends Model
{
    use Translatable;
}

Use Deepl integration

This package contains an integration with Deepl. This integration will add a button to the translations index view, that will automaticly translate your text via Deepl. Just add the following ENV variable to use this awesome feature.

TRANSLATABLE_DEEPL_API_KEY=

This will use the free version of the Deepl API. If you have a paid subscription, you can add the following as well.

TRANSLATABLE_DEEPL_API_PATH=https://api.deepl.com

Configuration

After publishing, the configuration lives in config/translatable.php:

Key Default Description
driver database Translation storage driver. Supported: file, database. Migrations are only loaded when set to database.
nova_translatable_fields true Show the language selector when editing a resource in Laravel Nova.
flag_icon ['height' => 40, 'width' => 40] Ratios for the flag uploader.
translation_methods ['trans', '__'] Methods the scanner looks for when finding missing translations.
scan_paths [app_path(), resource_path()] Directories scanned when looking for missing translations.
models Language, Translation, Translatable, MissingTranslation Model classes used by the package. Override to swap in your own.
force_locale_query_string force_locale Query string parameter that forces the locale, useful for testing and deep linking.
deepl.api_path env('TRANSLATABLE_DEEPL_API_PATH', 'https://api-free.deepl.com') Deepl API endpoint.
deepl.api_key env('TRANSLATABLE_DEEPL_API_KEY') Deepl API key.
auto_translator.active env('TRANSLATABLE_AUTO_TRANSLATOR_ACTIVE', false) Enable the auto-translator.
missing_translations.active env('MISSING_TRANSLATIONS_ACTIVE', false) Enable missing-translation tracking.

Artisan Commands

The package ships the following Artisan commands:

Command Description
translatable:install Install the package: update config, sync files to database and generate Nova resources.
translatable:add-language Add a new language.
translatable:add-translation-key Add a new translation key.
translatable:list-languages List the configured languages.
translatable:list-missing List missing translation keys.
translatable:sync-file-to-database Sync existing language files into the database.
translatable:sync-missing Sync missing translation keys.
translatable:sync-translations Synchronise translations.
translatable:duplicates Find duplicate translations.
translatable:fix-placeholders Fix translated placeholders.
translatable:generate-preset Generate a preset.
translatable:preset Apply a preset.
translatable:index-missing-translatables Index missing translatables.

Security

If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

marshmallow/translatable 适用场景与选型建议

marshmallow/translatable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.84k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 10 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「translatable」 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 marshmallow/translatable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 marshmallow/translatable 我们能提供哪些服务?
定制开发 / 二次开发

基于 marshmallow/translatable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.84k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 23
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-07