承接 codecng/laravel-inertia-translations 相关项目开发

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

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

codecng/laravel-inertia-translations

最新稳定版本:1.2.1

Composer 安装命令:

composer require codecng/laravel-inertia-translations

包简介

Provides translations for an Inertia Based Project

README 文档

README

Latest Version on Packagist Total Downloads

A zero-configuration Laravel package that automatically exports your Laravel translations for use with Inertia.js. Supports both React and Vue, with full TypeScript support!

Installation

composer require codecng/laravel-inertia-translations

That's it! No additional configuration needed.

Usage

Whenever you add or modify translations in your Laravel application, simply run:

php artisan translate

This command will:

  1. Check if language files exist (if not, it will publish them automatically)
  2. Process all your translation files (both JSON and PHP)
  3. Generate JSON translation files in resources/js/lang/
  4. Create appropriate utility files based on your stack (React/Vue + TypeScript)

What Gets Processed

  • ✅ JSON files in lang/ directory
  • ✅ PHP files in language subdirectories
  • ✅ Automatically merges all translations by locale

Generated Files Structure

resources/js/
├── lang/
│   ├── en.json
│   ├── es.json
│   └── fr.json
└── lib/
    └── translations.(js|ts|jsx|tsx)  # Based on your stack

Framework Support

React

import { __ } from '@/lib/translations'

function Welcome() {
    return (
        <div>
            <h1>{__('welcome.title')}</h1>
            <p>{__('welcome.message')}</p>
            <p>{__('Users')}</p>
        </div>
    )
}

Vue

<script setup>
import { __ } from '@/lib/translations'
</script>

<template>
    <div>
        <h1>{{ __('welcome.title') }}</h1>
        <p>{{ __('welcome.message') }}</p>
    </div>
</template>

Inertia Setup

Make sure to include the current language in your Inertia shared props (in your HandleInertiaRequests middleware):

public function share(Request $request): array
{
    return array_merge(parent::share($request), [
        'language' => request()->user()->language ?? app()->getLocale(),
    ]);
}

Type Support

When using TypeScript, you get full type support for your translation keys:

// The __ function is fully typed
__('welcome.title') // ✓ Valid
__('invalid.key')   // ✗ TypeScript error

Benefits

  • 🚀 Zero configuration required
  • 🔄 Simple one-command updates
  • 🛠 Works with both JSON and PHP translation files
  • 💪 Full TypeScript support
  • ⚡️ Supports both React and Vue
  • 🔍 Automatic type generation for translation keys

Credits

License

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

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固