piko/i18n 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

piko/i18n

最新稳定版本:v2.3

Composer 安装命令:

composer require piko/i18n

包简介

A minimal internationalization component that can be used in a piko application or standalone.

README 文档

README

build Coverage Status

A minimal internationalization component which can be used in a piko application or standalone.

Installation

It's recommended that you use Composer to install Piko I18n.

composer require piko/i18n

Usage

In order to use the I18n component, translations have to be stored in PHP files that return a key-value pair array of translations. Keys are strings to translate and values are corresponding translated strings.

Example of translation file fr.php :

return [
    'Translation test' => 'Test de traduction',
    'Hello {name}' => 'Bonjour {name}',
];

Application structure example:

App root
  |__messages
    |__fr.php
  |__index.php

Usage in a piko application

index.php :

use Piko\Application;
use function Piko\I18n\__;

require('vendor/autoload.php');

$config = [
    'basePath' => __DIR__,
    'components' => [
        'Piko\I18n' => [
            'translations' => [
                'app' => '@app/messages',
            ],
            'language' => 'fr'
        ],
    ],
];

$app = new Application($config);

$i18n = $app->getComponent('Piko\I18n');

echo $i18n->translate('app', 'Translation test') . '<br>'; // Test de traduction
echo $i18n->translate('app', 'Hello {name}', ['name' => 'John']) . '<br>' ; // Bonjour John

// Using the proxy function __() :
I18n::setInstance($i18n); // Required to use the function __()
echo __('app', 'Translation test') . '<br>'; // Test de traduction
echo __('app', 'Hello {name}', ['name' => 'John']) . '<br>' ;  // Bonjour John

Usage in a standalone script

use Piko\I18n;
use function Piko\I18n\__;

require('vendor/autoload.php');

$i18n = new I18n(['app' => __DIR__ . '/messages'], 'fr');

echo $i18n->translate('app', 'Translation test') . '<br>';
echo $i18n->translate('app', 'Hello {name}', ['name' => 'John']) . '<br>' ;

// Using the proxy function __() :
I18n::setInstance($i18n); // Required to use the function __()
echo __('app', 'Translation test') . '<br>';
echo __('app', 'Hello {name}', ['name' => 'John']) . '<br>' ;

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2022-10-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固