rene-roscher/laravel-i18n-json-converter 问题修复 & 功能扩展

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

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

rene-roscher/laravel-i18n-json-converter

最新稳定版本:1.0.2

Composer 安装命令:

composer require rene-roscher/laravel-i18n-json-converter

包简介

A Package for Laravel that converts PHP array-based translation files into flattened JSON files, making them compatible with Vue i18n

README 文档

README

PVM Banner

A Package for Laravel that converts PHP array-based translation files into flattened JSON files, making them compatible with e.g. xiCO2k/laravel-vue-i18n

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

A Package for Laravel that converts PHP array-based translation files into flattened JSON files, making them compatible with xiCO2k/laravel-vue-i18n.

Installation

You can install the package via composer:

composer require rene-roscher/laravel-i18n-json-converter

You can convert your PHP array-based translation files into flattened JSON files by running the following command:

php artisan i18n:convert

Configure i18n for vue-i18n

import { i18nVue } from 'laravel-vue-i18n'

// Register the i18n plugin like this
// Tested with Vue 3 (Inertia) and Vite 4
// You need to add the locales manually to the switch, dynamic loading is not supported yet
app.use(i18nVue, {
    resolve: async (lang) => {
        const langFiles = import.meta.glob('../lang/*.json', { eager: true })

        let modules
        switch (lang) {
            case 'en':
                modules = import.meta.glob('../lang/json/en/*.json', { eager: true })
                break
            case 'de':
                modules = import.meta.glob('../lang/json/de/*.json', { eager: true })
                break
        }

        const messages = langFiles[`../lang/${lang}.json`] || {}

        for (const path in modules) {
            const regex = new RegExp(`../lang/json/${lang}/(.+)\\.json$`)
            const match = path.match(regex)
            if (match) {
                const prefix = match[1]
                const moduleMessages = modules[path].default
                for (const key in moduleMessages) {
                    messages.default[`${prefix}.${key}`] = moduleMessages[key]
                }
            }
        }

        return messages
    }
})

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

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

统计信息

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

GitHub 信息

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

其他信息

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