jv/jvfurigana
Composer 安装命令:
composer require jv/jvfurigana
包简介
A view helper that can convert plain japanese text into properly formatted HTML with furigana (using the ruby tag).
README 文档
README
ZF2 Module for adding furigana to japanese text
Version 1.0 Created by Julian Vidal
What exactly is furigana?
Furigana according to Wikipedia is:
A Japanese reading aid, consisting of smaller kana, or syllabic characters, printed next to a kanji (ideographic character) or other character to indicate its pronunciation. It is typically used to clarify rare, nonstandard or ambiguous readings, or in children's or learners' materials.
Simply put, you could know how to read a certain word in Japanese but that doesn't necessarily mean that you know how to pronounce it. To solve this problem, publishers use furigana to tell the reader how a particular word is pronounced.
A Japanese sentence looks like this:
林さんは英語は話せます。
To add a phonetic guide it is common practice to include the pronunciations between parenthesis right after the kanji, like this:
林(はやし)さんは英語(えいご)は話(はな)せます。
While this makes pronunciations very clear it makes the text less readable.
This module takes furigana entered in the above format and converts it to proper HTML using ruby, rb, rp, and rt tags. This will turn the above sentence into this:
<ruby><rb>林</rb><rp>(</rp><rt>はやし</rt><rp>)</rp></ruby>さんは<ruby><rb>英語</rb><rp>(</rp><rt>えいご</rt><rp>)</rp></ruby>は<ruby><rb>話</rb><rp>(</rp><rt>はな</rt><rp>)</rp></ruby>せます。
Supported browsers (like Chrome) will render it like this:
And a nice advantage is that browsers that don't support ruby text will degrade gracefully and render your text exactly as you entered it. Actually the text will look the same but since the furigana will now be wrapped in its own tags, you will be able to style them the way you want. You couldn't have done this without ruby tags. So as you see the ruby tag has its benefits.
Installation
You can install this module in different ways. The easiest one is by using composer. For this to work you need to add the module to your require section in the composer.json file:
"require": {
"jv/jvfurigana": "dev-master"
}
Then run: php composer.phar update
If you don't want to use composer, you can clone or download this repository into your ZF2 modules directory.
Whatever way you choose, don't forget to enable the module in your config/application.config.php file.
Usage
From within a view script, you can do:
<?=$this->jvfurigana('こんにちは世界(せかい)'); ?>
PERFORMANCE
The view helper needs to be initialized with a render strategy that implements the RenderStrategyInterface. By default it implements the FilterStrategy which will work fine with PHP 5.3. In some windows installs I noticed that this strategy was not catching all the furigana correctly. If that is your case, you can use the ManualStrategy which, as the name implies, does a lot of the work manually.
You should always use the FilterStrategy because it outperforms the ManualStrategy by far. Rendering 40 kilobytes of japanese text with FilterStrategy took 0.002 seconds while the ManualStrategy took 18.177 seconds on a MacBook Pro i7 with 16gb of ram.
FAQ
See the github FAQ page.
License
JVFurigana is released under the Apache license. See the included LICENSE file.
VERSION HISTORY
2012-11-18 Added filter strategy 2012-11-11 First version
jv/jvfurigana 适用场景与选型建议
jv/jvfurigana 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 6, 最近一次更新时间为 2012 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「zf2」 「japanese」 「kanji」 「furigana」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jv/jvfurigana 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jv/jvfurigana 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jv/jvfurigana 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Translate comments in laravel/laravel 5.* project to Japanese
A php Japanese language text analyzer and parser.
LosLog provides some log utility
EdpModuleLayouts is very simple Laminas module for making module-specific layouts insanely easy.
Zend Framework module to leverage the symfony dependency injection container
RCM User HTML views/pages
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2012-11-12