1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-03-21 15:59:52 +01:00

Update Ukrainian characters

This commit is contained in:
ruden 2013-11-04 11:18:08 +02:00
parent 872d21c62d
commit c18e92dd30
2 changed files with 21 additions and 68 deletions

View File

@ -7,6 +7,21 @@ class Internet extends \Faker\Provider\Internet
protected static $tld = array('ua', 'com.ua', 'org.ua', 'net.ua', 'com', 'net', 'org');
protected static $freeEmailDomain = array('gmail.com', 'mail.ru', 'ukr.net', 'i.ua', 'rambler.ru');
/**
* Converts Ukrainian characters to their ASCII representation
*
* {@link} http://ru.wikipedia.org/wiki/%D0%A2%D1%80%D0%B0%D0%BD%D1%81%D0%BB%D0%B8%D1%82%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F_%D1%83%D0%BA%D1%80%D0%B0%D0%B8%D0%BD%D1%81%D0%BA%D0%BE%D0%B3%D0%BE_%D0%B0%D0%BB%D1%84%D0%B0%D0%B2%D0%B8%D1%82%D0%B0_%D0%BB%D0%B0%D1%82%D0%B8%D0%BD%D0%B8%D1%86%D0%B5%D0%B9
*
* @return string
*/
private static function toAscii($string)
{
$from = array('А', 'Б', 'В', 'Г', 'Ґ', 'Д', 'Е', 'Є', 'Ж', 'З', 'И', 'І', 'Ї', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ь', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'ґ', 'д', 'е', 'є', 'ж', 'з', 'и', 'і', 'ї', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ь', 'ю', 'я', '\'', '`');
$to = array('a', 'b', 'v', 'g', 'g', 'd', 'e', 'ye', 'zh', 'z', 'y', 'i', 'yi', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'kh', 'ts', 'ch', 'sh', 'shch', '', 'yu', 'ya', 'a', 'b', 'v', 'g', 'g', 'd', 'e', 'ye', 'zh', 'z', 'y', 'i', 'yi', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'kh', 'ts', 'ch', 'sh', 'shch', '', 'yu', 'ya', '', '');
return str_replace($from, $to, $string);
}
/**
* @example 'roman93'
*/
@ -14,10 +29,7 @@ class Internet extends \Faker\Provider\Internet
{
$format = static::randomElement(static::$userNameFormats);
return static::toLower(static::bothify(
Transliteration::transliterate($this->generator->parse($format))
)
);
return static::toLower(static::toAscii(static::bothify($this->generator->parse($format))));
}
/**
@ -25,10 +37,11 @@ class Internet extends \Faker\Provider\Internet
*/
public function domainWord()
{
$company = $this->generator->format('companyUrl');
$company = str_replace(' ', '-', $company);
$company = Transliteration::transliterate($company);
$company = $this->generator->format('company');
$companyElements = explode(' ', $company);
$company = $companyElements[0];
$company = preg_replace('/\W/u', '', $company);
return $company;
return static::toLower(static::toAscii($company));
}
}

View File

@ -1,60 +0,0 @@
<?php
namespace Faker\Provider\uk_UA;
/**
* Cyrillic to latin transliteration util
*/
class Transliteration
{
/**
* Translate cyrillic text to latin
* Useful for URL ang email generation
* @param string $string
* @return string
*/
public static function transliterate($string = '')
{
$replace=array(
"'"=>"",
"`"=>"",
"а"=>"a","А"=>"a",
"б"=>"b","Б"=>"b",
"в"=>"v","В"=>"v",
"г"=>"g","Г"=>"g",
"д"=>"d","Д"=>"d",
"е"=>"e","Е"=>"e",
"ж"=>"zh","Ж"=>"zh",
"з"=>"z","З"=>"z",
"и"=>"i","И"=>"i",
"й"=>"y","Й"=>"y",
"к"=>"k","К"=>"k",
"л"=>"l","Л"=>"l",
"м"=>"m","М"=>"m",
"н"=>"n","Н"=>"n",
"о"=>"o","О"=>"o",
"п"=>"p","П"=>"p",
"р"=>"r","Р"=>"r",
"с"=>"s","С"=>"s",
"т"=>"t","Т"=>"t",
"у"=>"u","У"=>"u",
"ф"=>"f","Ф"=>"f",
"х"=>"h","Х"=>"h",
"ц"=>"c","Ц"=>"c",
"ч"=>"ch","Ч"=>"ch",
"ш"=>"sh","Ш"=>"sh",
"щ"=>"sch","Щ"=>"sch",
"ъ"=>"","Ъ"=>"",
"ы"=>"y","Ы"=>"y",
"ь"=>"","Ь"=>"",
"э"=>"e","Э"=>"e",
"ю"=>"yu","Ю"=>"yu",
"я"=>"ya","Я"=>"ya",
"і"=>"i","І"=>"i",
"ї"=>"yi","Ї"=>"yi",
"є"=>"e","Є"=>"e"
);
return strtr($string, $replace);
}
}