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.
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
nobox/lazy-strings 适用场景与选型建议
nobox/lazy-strings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 737 次下载、GitHub Stars 达 5, 最近一次更新时间为 2014 年 08 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「spreadsheet」 「googledocs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nobox/lazy-strings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nobox/lazy-strings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nobox/lazy-strings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
Adds support for dynamic translations from Google Spreadsheets.
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
统计信息
- 总下载量: 737
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 13
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-08-23