servergrove / servergrovelocalebundle
此包已被废弃,不再维护。未建议替代包。
此包提供了一组Twig函数,用于以不同方式显示旗帜。
v2.0.0
2013-07-23 15:21 UTC
Requires
- kriswallsmith/assetic: >=1.0
- symfony/config: ~2.1
- symfony/dependency-injection: ~2.1
- symfony/finder: ~2.1
- symfony/http-kernel: ~2.1
- twig/twig: >=1.4,<2.0
Requires (Dev)
- symfony/filesystem: ~2.1
- symfony/routing: ~2.1
- symfony/twig-bridge: ~2.1
This package is not auto-updated.
Last update: 2020-12-18 04:34:38 UTC
README
此包提供了一组Twig函数,用于显示浏览器文化代码。
安装
您需要根据您的Symfony版本遵循以下步骤。
Symfony 2.0的特定要求
依赖项
首先,您需要将包添加到您的deps文件中
[ServerGroveLocaleBundle]
git=https://github.com/servergrove/ServerGroveLocaleBundle.git
target=bundles/ServerGrove/LocaleBundle
然后,运行 vendors 脚本以下载包源代码
$ php ./bin/vendors install
自动加载
应用程序必须知道在哪里查找我们的包类。将以下行添加到自动加载文件中即可。
<?php // app/autoload.php $loader->registerNamespaces(array( // ... 'ServerGrove' => __DIR__.'/../vendor/bundles', ));
Symfony 2.1的特定要求
{ "require": { "servergrove/ServerGroveLocaleBundle": "dev-master" } }
启用包
现在,我们需要告诉我们的应用程序内核启用此包。为此,我们需要向内核包中添加一个包实例。
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new ServerGrove\LocaleBundle\ServerGroveLocaleBundle(), ); }
配置
使用默认设置
server_grove_locale: ~
或根据您的需求进行配置
server_grove_locale: # The path where to look for flag images flags_path: "/path/to/flags" # Default: /path/to/ServerGroveLocaleBundle/Resources/public/images # Whether should or shouldn't be displayed the active flag hide_current_locale: true # Default: true # Cache warmer options cache_warmer: enabled: true # Default: true patterns: [ "/^(?P<locale>[a-z]{2}).png$/" ] # Default: [ "/^(?P<locale>[a-z]{2}).png$/", "/^(?P<locale>[a-z]{2})\-(?P<country>[A-Z]{2}).png$/" ] defaults: # Default: [] en: "en-UK.png" # Twig template with functions template: "AcmeDemoBundle::template.html.twig" # Default: ServerGroveLocaleBundle::flags.html.twig # Flags loader loader: class: "My\Loader\Class" # Default: ServerGrove\LocaleBundle\Flag\CacheLoader arguments: [] # Default: [ "%kernel.cache_dir%" ] # Use different domains for different locales domains: - { locale: "en", domain: "example.com", default: true } - { locale: "es", domain: "example.es" } # Set which flags should be displayed enabled_locales: [ "en", "es*" ]
显示单个旗帜
有三个有用的函数用于显示单个旗帜。
flag 函数
flag 函数仅显示旗帜图片
{{ flag(locale) }}
{{ flag(locale, country) }}
结果将是
<img src="/images/locale/flags-en.png"/>
您还可以使用带有选项的第三个参数。
属性
其中一个可用选项是 attrs,它允许向图片添加属性。
{{ flag(locale, country, {
attrs: {
alt: "My locale flag",
title: "The title of my flag"
}
}) }}
如果您为特定属性设置了数组,则必须指定该属性适用于哪种区域。
{{ flag(locale, country, {
attrs: {
alt: {
en: "My locale flag in English",
},
title: "The title of my flag"
}
}) }}
path_flag 函数
此包提供了一个函数,用于显示带有特定 route 链接的旗帜。
{{ path_flag(route, locale) }}
{{ path_flag(route, locale, route_params, country, options) }}
结果将是
<a href="/page/en"><img src="/images/locale/flags-en.png"/></a>
domain_flag 函数
它还提供了一个函数,将旗帜链接到配置的域。
{{ domain_flag(locale) }}
{{ domain_flag(locale, country, options) }}
结果将是
<a href="http://example.com"><img src="/images/locale/flags-en.png"/></a>
显示多个配置的旗帜
通过本节,您将能够使用一个函数显示多个旗帜。
flags 函数
flags 函数是 flag 函数的多个图像等效函数。
{{ flags() }}
{{ flags(options) }}
结果将是
<img src="/images/locale/flags-en.png"/> <img src="/images/locale/flags-es.png"/>
path_flags 函数
path_flags 函数是针对多张图像的 path_flag 函数的等效函数。路由的 _locale 参数会自动设置。
{{ path_flags(route) }}
{{ path_flags(route, route_params, options) }}
结果将是
<a href="/page/en"><img src="/images/locale/flags-en.png"/></a> <a href="/page/es"><img src="/images/locale/flags-es.png"/></a>
domains_flags 函数
domains_flags 函数是针对多张图像的 domains_flags 函数的等效函数。
{{ domains_flags() }}
{{ domains_flags(options) }}
结果将是
<a href="http://example.com"><img src="/images/locale/flags-en.png"/></a> <a href="http://example.es"><img src="/images/locale/flags-es.png"/></a>