pointdeb/translator

基于键和值的 Laravel 框架动态翻译文件生成器。

v0.1.0 2019-01-05 21:33 UTC

This package is auto-updated.

Last update: 2024-09-07 05:14:12 UTC


README

Translator 是一个基于键和值的 Laravel 框架动态翻译文件生成器;

安装

composer require pointdeb/translator

用法

SaveToFile

<?php

use Pointdeb\Translator\Translation;

$datas = [
    "home.cover.greeting" => [
        "en" => "Hello world",
        "fr" => "Salut les gens",
        "mg" => "Salama tompoko"
    ],
];

$outputPath = '/your/path/';

foreach($datas as $key => $data) {
  $result = Translation::saveToFile($key, $data, $outputPath);
}

// result /your/path/en/home.php 
/** 
 * <?php
 * $contents = [];
 * $contents['cover']['greeting'] = "Hello world";
 * $contents['cover']['getstarted'] = "Get Started";
 * return $contents;
 */

GetFromExcel

use Pointdeb\Translator\Translation;

$excel = '/path/to/your.xlsx';
$result = Translation::getFromExcel($excel);

/**
 * [
 *      'key' => [
 *          'en' => 'value',
 *          'fr' => 'valeur'            
 *      ]
 * ] 
 * 
*/

SaveToFileFromExcel (GetFromExcel 和 SaveToFile 的合并)

use Pointdeb\Translator\Translation;

$outputPath = '/your/path/';
$excel = '/path/to/your.xlsx';

$result = Translation::saveToFileFromExcel($excel, $outputPath);

// result /your/path/en/home.php 
/** 
 * <?php
 * $contents = [];
 * $contents['cover']['greeting'] = "Hello world";
 * $contents['cover']['getstarted'] = "Get Started";
 * return $contents;
 */

测试

phpunit

用爱💖制作,即将带来更多精彩内容,@Pointdeb