didublab / cookielaw
一个简单的 Symfony 扩展包,用于显示 cookie 法律通知。
1.1.0
2020-06-05 21:39 UTC
Requires
- php: ^7.2
- symfony/framework-bundle: ^4.3 || ^5.0
- symfony/routing: ^4.3 || ^5.0
- symfony/translation: ^4.3 || ^5.0
- twig/twig: ^2.0 || ^3.0
This package is auto-updated.
Last update: 2024-09-06 08:21:52 UTC
README
这是一个简单的 Symfony 扩展包,用于在您的 Symfony 4 和 Symfony 5 项目上通过简单的配置显示 cookie 法律通知。
安装扩展包
使用 composer
composer require didublab/cookielaw
渲染 cookie 法律通知
在您的 twig 模板中,添加您想加载 cookie 同意的函数
{{ cookie_law() }}
这是最小配置,但如果你需要更多,你可以配置一些选项
配置选项
在您的 config/packages/ 目录中创建一个新的配置文件,例如:cookie_law.yaml。以下是可用的选项及其默认值
didublab_cookielaw: cookie_name: cookie-notice-accepted #the cookie name cookie_value: true #the cookie value cookie_days: 10 #cookie expiration in days cookie_readmore_route: false #the route where you want to redirect the users to the "read more" section
翻译
您可以根据需要翻译 cookie 法律通知的文本
- 在翻译目录中创建一个名为 cookielaw.(language).xliff 的文件
- 在里面添加以下内容,并将 "target" 标签替换为您的翻译
<?xml version="1.0"?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" target-language="en" datatype="plaintext" original="file.ext"> <body> <trans-unit id="didublab_cookielaw_cookie_text"> <source>didublab_cookielaw_cookie_text</source> <target>This website use cookies. By continuing to browse this website, you declare to accept the use of cookies.</target> </trans-unit> <trans-unit id="didublab_cookielaw_cookie_accept"> <source>didublab_cookielaw_cookie_accept</source> <target>Accept</target> </trans-unit> <trans-unit id="didublab_cookielaw_cookie_readmore"> <source>didublab_cookielaw_cookie_readmore</source> <target>More info</target> </trans-unit> </body> </file> </xliff>