nobox/lazy-strings 问题修复 & 功能扩展

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

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

nobox/lazy-strings

Composer 安装命令:

composer require nobox/lazy-strings

包简介

Create localized strings from a Google Docs Spreadsheet.

README 文档

README

Create localized strings from a Google Docs Spreadsheet.

Build Status

Installation

Add Lazy Strings to your composer.json file.

composer require nobox/lazy-strings

Usage

Create an instance of LazyStrings with the following settings.

$lazyStrings = new LazyStrings([
    'url' => 'http://docs.google.com/spreadsheets/d/1V_cHt5Fe4x9XwVepvlXB39sqKXD3xs_QbM-NppkrE4A/export?format=csv',
    'sheets' => [
        'en' => 0,
    ],
    'target' => 'path/to/strings/folder',
    'backup' => 'path/to/strings/folder',
    'nested' => true
]);

And generate your strings with the generate(); method.

$lazyStrings->generate();

Settings

Each setting key item is described below.

url

Add the Google spreadsheet published url. This should be done with File -> Publish to the web..., replace pubhtml with export?format=csv at the end and use http on the url. Remember that this document must be available to anyone. Use Public on the web on your Sharing settings. If not, Lazy Strings won't be able to parse it.

'url' => 'http://docs.google.com/spreadsheets/d/1V_cHt5Fe4x9XwVepvlXB39sqKXD3xs_QbM-NppkrE4A/export?format=csv'

sheets

Here you'll specify all the sheets in your Google doc (if it's more than one) with their id, each separated by locale. Use an array if using more than one sheet for a locale. Example:

'sheets' => [
    'en' => [0, 1626663029],
    'es' => 1329731586,
    'pt' => 1443604037
]

You can take the id from the spreadsheet using the gid variable from your Google doc url. For example, in this spreadsheet: https://docs.google.com/a/nobox.com/spreadsheets/d/1V_cHt5Fe4x9XwVepvlXB39sqKXD3xs_QbM-NppkrE4A/edit#gid=1626663029 the id is 1626663029.

target

Here you must specify a path where to store your translations.

'target' => 'path/to/strings/folder'

Using these settings it will generate the following translation files in path/to/strings/folder.

├── folder/
│   ├── en/
│   │   ├── lazy.php
│   ├── es/
│   │   ├── lazy.php
│   ├── pt/
│   │   ├── lazy.php

backup

Here you must specify a path where to store your translations in JSON format. More like a "backup" of your strings.

'backup' => 'path/to/strings/folder'

Using these settings it will generate the following translation files in path/to/strings/folder.

├── folder/
│   ├── es.json
│   ├── en.json
│   ├── pt.json

nested

Specify whether or not you want your translations array to be nested.

'nested' => true

If you use the nested setting as true your translations will look like something like this:

<?php return array (
    'title' => 'Your page title',
    'tagline' => 'Your page tagline',
    'laravel' => 'PHP Framework',
    'header' => array (
        'hero' => array (
            'headline' => 'Hero headlines',
            'subject' => 'Main hero subject',
        ),
    ),
);

And like this with false.

<?php return array (
    'title' => 'Your page title',
    'tagline' => 'Your page tagline',
    'laravel' => 'PHP Framework',
    'header.hero.headline' => 'Hero headlines',
    'header.hero.subject' => 'Main hero subject',
);

How it works

Lazy Strings uses an id => value convention to access the copy, it generates a lazy.php file inside the specified language locale folder. You can see an example doc here.

id value
title Your page title
tagline Your page tagline
laravel PHP Framework
header.hero.headline Hero headlines
header.hero.subject Main hero subject

Using this example doc (with nested translations) you can access the first row like this:

$locale = 'en';
$strings = require 'path/to/strings/folder/'.$locale.'/lazy.php';
echo $strings['title']; // Returns "Your page title"

License

MIT

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-08-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固