liip / hyphenator-bundle
此包已被弃用,不再维护。未建议替代包。
此Bundle提供了使用Org_Heigl_Hyphenator库进行长词分词的支持
2.0.0
2015-10-24 15:12 UTC
Requires
- php: >=5.3.9
- org_heigl/hyphenator: ~2.0
- symfony/framework-bundle: ~2.3|~3.0
- twig/twig: ~1.20|~2.0
Requires (Dev)
- symfony/browser-kit: ~2.3|~3.0
- symfony/twig-bundle: ~2.3|~3.0
README
添加使用Org_Heigl_Hyphenator库进行长词分词的支持。
此bundle将为模板添加一个Twig扩展和一个分词服务。
安装
-
下载Bundle
打开命令行,进入项目目录,执行以下命令以下载此bundle的最新稳定版本
$ composer require liip/hyphenator-bundle
此命令需要您全局安装Composer,请参阅Composer文档中的安装章节。
-
启用Bundle
在
app/AppKernel.php
文件中添加以下行以仅启用此bundle的test
环境<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { .. new Liip\HyphenatorBundle\LiipHyphenatorBundle(), return $bundles } // ... }
-
配置Bundle
Hyphenator支持的选项(默认值)如下
# app/config/config.yml liip_hyphenator: default_locale: 'en_GB' hyphen: ­ left_min: 2 right_min: 2 word_min: 6 quality: highest # either the quality name, either the value of the constant no_hyphenate_string: '' custom_hyphen: -- tokenizers: ['liip_hyphenator.tokenizer.whitespace', 'liip_hyphenator.tokenizer.punctuation'] filters: ['liip_hyphenator.filter.simple']
所有设置都是可选的。 注意:
default_locale
需要是一个完全限定的区域设置,如en_EN
,en
将不起作用。有关它们的意义,请参阅Hyphenator库文档。
使用
此库为twig模板添加了一个过滤器,可以使用如下:
{{ "Somelongwordtohyphenate"|hyphenate }}
或者,可以将过滤器应用于整个块
{% filter hyphenate %}
...
Somelongwordtohyphenate
....
{% endfilter %}
此外,还可以传递一个区域设置作为参数,如果不需要使用默认区域设置的话
{{ "Somelongwordtohyphenate"|hyphenate("de") }}