places2be/locales 问题修复 & 功能扩展

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

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

places2be/locales

最新稳定版本:3.3.0

Composer 安装命令:

composer require places2be/locales

包简介

Handling country codes and language codes

README 文档

README

PHP from Packagist Latest Stable Version Total Downloads License

Bit&Black Logo

Places2Be Locales

Handling country codes and language codes in an object-oriented way.

TOC

Installation

This library is made for the use with Composer. Add it to your project by running $ composer require places2be/locales.

Usage

Handling country codes

Set up a country code like that:

<?php

use Places2Be\Locales\CountryCode;

$countryCode = new CountryCode('de');

The script will only accept country codes having a length of two characters and will throw an InvalidCountryCode exception otherwise.

Per default, the script will proof if the country code exists. You can change this behaviour in two ways:

<?php

use Places2Be\Locales\CountryCode;

/**
 * 1. Disable the validation globally: 
 */
CountryCode::ignoreCountriesExistence();

/**
 * 2. Disable the validation only for the current object:
 */
$countryCode = new CountryCode('xx', ignoreCountryExistence: true);

Instead of initializing the class with a string you can also use the CountryCodesEnum:

<?php

use Places2Be\Locales\CountryCode;
use Places2Be\Locales\CountryCodesEnum;

$countryCode = new CountryCode(
    CountryCodesEnum::DE
);

Handling language codes

Set up a language code like that:

<?php

use Places2Be\Locales\LanguageCode;

$languageCode = new LanguageCode('de-ch');

Per default, the script will proof if the language code exists. You can change this behaviour in two ways:

<?php

use Places2Be\Locales\LanguageCode;

/**
 * 1. Disable the validation globally: 
 */
LanguageCode::ignoreLanguagesExistence();

/**
 * 2. Disable the validation only for the current object:
 */
$languageCode = new LanguageCode('xx-yy', ignoreLanguageExistence: true);

Per default, the class will only accept language codes written like that: xx-xx (or xxx-xx) and will throw an InvalidLanguageCode exception otherwise.

If you want to use country-unspecific language codes like de instead of de-de you can allow that in two ways:

<?php

use Places2Be\Locales\LanguageCode;

/**
 * 1. Disable the validation globally: 
 */
LanguageCode::allowCountryUnspecificLanguageCodes();

/**
 * 2. Disable the validation only for the current object:
 */
$languageCode = new LanguageCode('de', allowCountryUnspecificLanguageCode: true);

Instead of initializing the class with a string you can also use the LanguageCodesEnum:

<?php

use Places2Be\Locales\LanguageCode;
use Places2Be\Locales\LanguageCodesEnum;

$languageCode = new LanguageCode(
    LanguageCodesEnum::DE_DE
);

Handling the reading mode

You can also access the reading mode from a language code by calling the getReadingMode method. It will return a instance of the ReadingModeEnum.

<?php

use Places2Be\Locales\LanguageCode;

$languageCode = new LanguageCode('ar-ae');
$readingMode = $languageCode->getReadingMode();

Help

If you have any questions, feel free to contact us under hello@bitandblack.com.

Further information about Bit&Black can be found under www.bitandblack.com.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-11