samehdoush/lingua 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

samehdoush/lingua

Composer 安装命令:

composer require samehdoush/lingua

包简介

Add your Laravel language translations to your asset pipeline for use in Javascript packages like Vue or React.

README 文档

README

Stand With Ukraine Stand With Ukraine Russian Warship Go Fuck Yourself Made in Ukraine

Originally based on Zora, but was hard modified.

Generate translations into JS file

This library allows you to generate your Laravel translations to your asset pipeline for use in JavaScript packages like Vue. (React coming soon)

Requirements

  • Laravel: ^9.* through ^13.*
  • InertiaJS: ^1.*
  • VueJS: ^3.*
  • ViteJS: ^3.*

Installation

First, install the package via composer:

composer require samehdoush/lingua

The package will automatically register itself.

Next add an alias to your vite.config.js

 resolve: {
    alias: {
        ...
        'lingua-js': resolve(__dirname, 'vendor/cyberwolfstudio/lingua/dist/index.js')
    },
},

To build your Laravel translation into JS file, use:

php artisan lingua:generate

You can automate that process as you wish. But we recommend you a vite plugin called vite-plugin-run Install it using you package manager and just add this lines to your vite.config.js plugins section.

 run({
    name: "generate translations",
    run: ['php', 'artisan', 'lingua:generate'],
    pattern: ['resources/lang/**', 'lang/**'],
})

Example of usage: (running only at serve process)

{
            ...run([
                {
                    name: 'generate translations',
                    run: ['php', 'artisan', 'lingua:generate'],
                    pattern: ['resources/lang/**', 'lang/**'],
                },
                {
                    name: 'generate ziggy',
                    run: ['php', 'artisan', 'ziggy:generate'],
                    pattern: ['routes/**'],
                }
            ]),
            apply: 'serve'
        }

VueJS

In your resources/js/app.js and (if you use SSR) resources/js/ssr.js add imports

import { LinguaVue } from 'lingua-js'
import { Lingua } from './lingua'

and register LinguaVue plugin

...
.use(LinguaVue, {
    Lingua
})

Add locale key into your HandleInertiaRequest::share method

[
    ...
    locale' => fn() => app()->getLocale(),
    ...
]

That's how your application will know your initial locale.

React

Coming soon

Usage

In your template tag use it in Laravel style, like

__(key: string, replacers: array)

//or

trans(key: string, replacers: array)

You can also use trans in your setup function by injecting it.

const trans = inject('trans') 

Changelog

All changes made here will be described in Changelog.md file.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固