承接 abedmaatalla/slim-twig-translation 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

abedmaatalla/slim-twig-translation

Composer 安装命令:

composer require abedmaatalla/slim-twig-translation

包简介

Twig function for Illuminate\Translation\Translator in Slim framework

README 文档

README

This repository provides a twig extension class for the twig view parser. The class adds a translate helper function for the use in twig templates. The translator function tries to call the trans() function of an Illuminate\Translation\Translator object in the slim DI container.

How to install

using Composer

Create a composer.json file in your project root:

{
    "require": {
        "abedmaatalla/slim-twig-translation": "1.0.0"
    }
}

Then run the following composer command:

$ php composer.phar install

How to use

Create new folder for langauges

-- lang

  • -- en
    • -- file.php
  • -- fr
    • -- file.php

Tanslator

Set up your Tansloator

$container['translator'] = function ($c)
{
  // Register the English translator 'en'
  $translator = new Illuminate\Translation\Translator(new Illuminate\Translation\FileLoader(new Illuminate\Filesystem\Filesystem(), __DIR__ . '/lang'), 'en');
    // setLocal for new location 
    $translator->setLocale('fr');
    return $translator;
};

Slim

Set up your twig views as described in the SlimViews Repository. Add the extension to your parser extensions.

$container['view'] = function ($c)
{
  $view = new \Slim\Views\Twig('../resources/views');

  // add translator functions to Twig
  $view->addExtension(new \abedmaatalla\Slim\Twig\Extension\TranslationExtension($c->translator));

}

Twig template

In your twig template you would write:

  {{ translate('male') }}

You can also use the shorthand:

  {{ tans('male') }}

You can also use the shorthand:

  {{ _('male') }}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固