rancoud/i18n

I18N 包

2.0.0 2020-07-27 00:30 UTC

This package is auto-updated.

Last update: 2024-08-27 09:29:55 UTC


README

Packagist PHP Version Support Packagist Version Packagist Downloads Composer dependencies Test workflow Codecov composer.lock

I18N.

安装

composer require rancoud/i18n

如何使用它?

您需要一个名为 LANG.php 的文件,其中 LANG 是文件名。
它将包含一个键值数组

return [
    'Hello' => 'Bonjour'
];

您必须设置默认目录和语言

$defaultDirectory = '/path/to/translations/';
$defaultLanguage = 'en';
I18N::setDefaults($directory, $defaultLanguage);

操作

I18N::echo('Hello');
// it will produce in output 'Hello'

I18N::echo('another string');
// it will produce in output 'another string' because the key doesn't exist in the file

$string = I18N::get('Hello');
// it will return 'Hello'

// you can use different language file instead of the default one
$string = I18N::get('string in other lang', 'es');
// it will return the translation of 'string in other lang' present in the es.php file

I18N 方法

通用静态命令

  • setDefaults(directory: string, language: string):void
  • echo(key: string, [language: string = null]):void
  • get(key: string, [language: string = null]):string

如何开发

composer ci 用于 php-cs-fixer、phpunit 和覆盖率
composer lint 用于 php-cs-fixer
composer test 用于 phpunit 和覆盖率