定制 vsalvans/twig-translation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vsalvans/twig-translation

Composer 安装命令:

composer require vsalvans/twig-translation

包简介

Twig Translation Extension using YAML files

README 文档

README

Twig Translation Extension using YAML files

//TranslationTwigExtension is in include folder
$twig->addExtension(new TranslationTwigExtension($lang, __DIR__.'/locale'));

First argument is $lang and the second is the translation yaml files folder

/locale/es.yaml is the translation file

For instance in es.yaml

Hello: Hola
<a href="#">English</a>: <a href="#">Spanish</a>
Your name is @name: Your name is @name

In the twig template use trans function like this:

<h1>{{ "Hello" | trans }}</h1>
{{ "<a href=\"#\">English</a>" | trans | raw }} <!-- for translation of html content -->
<p>{{ "Your name is @name" | trans({"@name" : "víctor"}) }}</p>	<!-- for translation with tokens -->

You can add a language fallback usign the third parameter:

$twig->addExtension(new TranslationTwigExtension($lang, __DIR__.'/locale', $fallbackLanguage));

If there is no translation for the current language it searchs a translation in the fallback language files

You can add debug log file. It add a new entry for each translation failed

$twig->addExtension(new TranslationTwigExtension($lang, __DIR__.'/locale', $fallbackLanguage, $logfile));

Then in the terminal you can list all strings without translation buy typing:

$ cat log_file | sort -u

Alert!!

This project has been archived because is old and has vulnerabilities

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-05-18