Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit 9e5f464

Browse files
committed
Merge pull request #447 from huy95/vi-vn-provider
Add vi_VN provider
2 parents 0cc304a + 6df6f1f commit 9e5f464

File tree

5 files changed

+498
-0
lines changed

5 files changed

+498
-0
lines changed

src/Faker/Provider/vi_VN/Address.php

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
3+
namespace Faker\Provider\vi_VN;
4+
5+
class Address extends \Faker\Provider\Address
6+
{
7+
protected static $buildingNumber = array('####', '###', '##', '#');
8+
protected static $postcode = array('#####', '######', '#####-####');
9+
protected static $province = array(
10+
'An Giang', 'Bà Rịa - Vũng Tàu',
11+
'Bắc Giang', 'Bắc Kạn', 'Bạc Liêu',
12+
'Bắc Ninh', 'Bến Tre', 'Bình Định',
13+
'Bình Dương', 'Bình Phước', 'Bình Thuận',
14+
'Cà Mau', 'Cao Bằng', 'Đắk Lắk',
15+
'Đắk Nông', 'Điện Biên', 'Đồng Nai',
16+
'Đồng Tháp', 'Gia Lai', 'Hà Giang',
17+
'Hà Nam', 'Hà Tĩnh', 'Hải Dương',
18+
'Hậu Giang', 'Hòa Bình', 'Hưng Yên',
19+
'Khánh Hòa', 'Kiên Giang', 'Kon Tum',
20+
'Lai Châu', 'Lâm Đồng', 'Lạng Sơn',
21+
'Lào Cai', 'Long An', 'Nam Định',
22+
'Nghệ An', 'Ninh Bình', 'Ninh Thuận',
23+
'Phú Thọ', 'Quảng Bình', 'Quảng Nam',
24+
'Quảng Ngãi', 'Quảng Ninh', 'Quảng Trị',
25+
'Sóc Trăng', 'Sơn La', 'Tây Ninh',
26+
'Thái Bình', 'Thái Nguyên', 'Thanh Hóa',
27+
'Thừa Thiên Huế', 'Tiền Giang', 'Trà Vinh',
28+
'Tuyên Quang', 'Vĩnh Long', 'Vĩnh Phúc',
29+
'Yên Bái', 'Phú Yên',
30+
);
31+
protected static $city = array(
32+
'Cần Thơ', 'Đà Nẵng', 'Hải Phòng', 'Hà Nội', 'Hồ Chí Minh',
33+
);
34+
protected static $streetNameFormats = array(
35+
'Phố {{lastName}} {{middleName}} {{firstName}}',
36+
'Phố {{lastName}} {{middleName}} {{firstName}}',
37+
'Phố {{lastName}} {{middleName}} {{firstName}}',
38+
'Phố {{firstName}}',
39+
'Phố {{lastName}}',
40+
);
41+
protected static $streetAddressFormats = array(
42+
'{{buildingNumber}} {{streetName}}',
43+
);
44+
protected static $hamletNameFormats = array(
45+
'{{hamletPrefix}} {{middleName}} {{firstName}}',
46+
'{{hamletPrefix}} {{lastName}} {{firstName}}',
47+
'{{hamletPrefix}} {{firstName}} {{lastName}}',
48+
'{{hamletPrefix}} {{middleName}} {{firstName}}',
49+
'{{hamletPrefix}} {{lastName}} {{middleName}} {{firstName}}',
50+
'{{hamletPrefix}} {{firstName}}',
51+
'{{hamletPrefix}} {{lastName}}',
52+
'{{hamletPrefix}} ##',
53+
'{{hamletPrefix}} #',
54+
);
55+
protected static $hamletPrefix = array(
56+
'Thôn', 'Ấp',
57+
);
58+
protected static $wardNameFormats = array(
59+
'{{hamletPrefix}} {{middleName}} {{firstName}}',
60+
'{{hamletPrefix}} {{lastName}} {{firstName}}',
61+
'{{wardPrefix}} {{firstName}} {{lastName}}',
62+
'{{wardPrefix}} {{middleName}} {{firstName}}',
63+
'{{wardPrefix}} {{lastName}} {{middleName}} {{firstName}}',
64+
'{{wardPrefix}} {{firstName}}',
65+
'{{wardPrefix}} {{lastName}}',
66+
'{{wardPrefix}} ##',
67+
'{{wardPrefix}} #',
68+
);
69+
protected static $wardPrefix = array(
70+
'Phường', '',
71+
);
72+
protected static $districtNameFormats = array(
73+
'{{districtPrefix}} {{middleName}} {{firstName}}',
74+
'{{districtPrefix}} {{lastName}} {{firstName}}',
75+
'{{districtPrefix}} {{firstName}} {{lastName}}',
76+
'{{districtPrefix}} {{middleName}} {{firstName}}',
77+
'{{districtPrefix}} {{lastName}} {{middleName}} {{firstName}}',
78+
'{{districtPrefix}} {{firstName}}',
79+
'{{districtPrefix}} {{lastName}}',
80+
'{{districtPrefix}} ##',
81+
'{{districtPrefix}} #',
82+
);
83+
protected static $districtPrefix = array(
84+
'Quận', 'Huyện',
85+
);
86+
protected static $addressFormats = array(
87+
"{{streetAddress}}, {{wardName}}, {{districtName}}\n{{city}}",
88+
"{{streetAddress}}, {{wardName}}, {{districtName}}\n{{province}}",
89+
"{{buildingNumber}}, {{hamletName}}, {{wardName}}, {{districtName}}\n{{province}}",
90+
);
91+
protected static $country = array(
92+
'Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica (the territory South of 60 deg S)', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan',
93+
'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Bouvet Island (Bouvetoya)', 'Brazil', 'British Indian Ocean Territory (Chagos Archipelago)', 'British Virgin Islands', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi',
94+
'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Cook Islands', 'Costa Rica', 'Cote d\'Ivoire', 'Croatia', 'Cuba', 'Cyprus', 'Czech Republic',
95+
'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic',
96+
'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia',
97+
'Faroe Islands', 'Falkland Islands (Malvinas)', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern Territories',
98+
'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea-Bissau', 'Guyana',
99+
'Haiti', 'Heard Island and McDonald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary',
100+
'Iceland', 'India', 'Indonesia', 'Iran', 'Iraq', 'Ireland', 'Isle of Man', 'Israel', 'Italy',
101+
'Jamaica', 'Japan', 'Jersey', 'Jordan',
102+
'Kazakhstan', 'Kenya', 'Kiribati', 'Korea', 'Korea', 'Kuwait', 'Kyrgyz Republic',
103+
'Lao People\'s Democratic Republic', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg',
104+
'Macao', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar',
105+
'Namibia', 'Nauru', 'Nepal', 'Netherlands Antilles', 'Netherlands', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway',
106+
'Oman',
107+
'Pakistan', 'Palau', 'Palestinian Territory', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn Islands', 'Poland', 'Portugal', 'Puerto Rico',
108+
'Qatar',
109+
'Reunion', 'Romania', 'Russian Federation', 'Rwanda',
110+
'Saint Barthelemy', 'Saint Helena', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Martin', 'Saint Pierre and Miquelon', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia (Slovak Republic)', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia and the South Sandwich Islands', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Svalbard & Jan Mayen Islands', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic',
111+
'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Timor-Leste', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu',
112+
'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States of America', 'United States Minor Outlying Islands', 'United States Virgin Islands', 'Uruguay', 'Uzbekistan',
113+
'Vanuatu', 'Venezuela', 'Vietnam',
114+
'Wallis and Futuna', 'Western Sahara',
115+
'Yemen',
116+
'Zambia', 'Zimbabwe'
117+
);
118+
119+
public function hamletName()
120+
{
121+
$format = static::randomElement(static::$hamletNameFormats);
122+
123+
return static::bothify($this->generator->parse($format));
124+
}
125+
126+
public function hamletPrefix()
127+
{
128+
return static::randomElement(static::$hamletPrefix);
129+
}
130+
131+
public function wardName()
132+
{
133+
$format = static::randomElement(static::$wardNameFormats);
134+
135+
return static::bothify($this->generator->parse($format));
136+
}
137+
138+
public function wardPrefix()
139+
{
140+
return static::randomElement(static::$wardPrefix);
141+
}
142+
143+
public function districtName()
144+
{
145+
$format = static::randomElement(static::$districtNameFormats);
146+
147+
return static::bothify($this->generator->parse($format));
148+
}
149+
150+
public function districtPrefix()
151+
{
152+
return static::randomElement(static::$districtPrefix);
153+
}
154+
155+
/**
156+
* @example 'Hà Nội'
157+
*/
158+
public function city()
159+
{
160+
return static::randomElement(static::$city);
161+
}
162+
163+
/**
164+
* @example 'Bắc Giang'
165+
*/
166+
public static function province()
167+
{
168+
return static::randomElement(static::$province);
169+
}
170+
}

src/Faker/Provider/vi_VN/Color.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Faker\Provider\vi_VN;
4+
5+
class Color extends \Faker\Provider\Color
6+
{
7+
protected static $safeColorNames = array(
8+
'đen', 'xanh', 'ô liu',
9+
'tím ', 'vôi', 'xanh', 'bạc',
10+
'xám', 'vàng', 'trắng',
11+
);
12+
13+
protected static $allColorNames = array(
14+
'Hổ phách', 'Ametit', 'Xanh berin',
15+
'Xanh da trời', 'Be', 'Nâu sẫm',
16+
'Đen', 'Xanh lam', 'Nâu',
17+
'Da bò', 'Cam cháy', 'Hồng y',
18+
'Đỏ yên chi', 'Men ngọc', 'Anh đào',
19+
'Xanh hoàng hôn', 'Xanh nõn chuối', 'Xanh cô ban',
20+
'Đồng', 'San hô', 'Kem',
21+
'Đỏ thắm', 'Xanh lơ', 'Lục bảo',
22+
'Vàng kim loại', 'Xám', 'Xanh lá cây',
23+
'Vòi voi', 'Chàm', 'Ngọc thạch',
24+
'Kaki', 'Oải hương', 'Vàng chanh',
25+
'Hồng sẫm', 'Hạt dẻ', 'Cẩm quỳ',
26+
'Hoa cà', 'Lam sẫm', 'Ochre',
27+
'Ô liu', 'Da cam', 'Lan tím',
28+
'Lòng đào', 'Dừa cạn', 'Hồng',
29+
'Mận', 'Xanh thủy tinh', 'Hồng đất',
30+
'Tía', 'Đỏ', 'Cá hồi',
31+
'Đỏ tươi', 'Nâu đen',
32+
'Bạc', 'Nâu tanin', 'Mòng két',
33+
'Xanh Thổ', 'Đỏ son', 'Tím',
34+
'Xanh crôm', 'Trắng', 'Vàng',
35+
);
36+
}

src/Faker/Provider/vi_VN/Internet.php

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Faker\Provider\vi_VN;
4+
5+
class Internet extends \Faker\Provider\Internet
6+
{
7+
protected static $tld = array('com', 'com', 'com', 'com', 'com', 'com', 'biz', 'info', 'net', 'org', 'vn', 'com.vn', 'biz.vn', 'edu.vn', 'gov.vn', 'net.vn', 'org.vn', 'int.vn', 'ac.vn', 'pro.vn', 'info.vn', 'health.vn', 'name.vn', 'mil.vn');
8+
9+
/**
10+
* Convert Vietnamese characters to their ASCII representation
11+
*
12+
* @param string
13+
* @return string
14+
*/
15+
private static function toAscii($string)
16+
{
17+
$from = array(
18+
'/á|à|ả|ã|ạ|ă|ắ|ặ|ằ|ẳ|ẵ|â|ấ|ầ|ẩ|ẫ|ậ|Á|À|Ả|Ã|Ạ|Ă|Ắ|Ặ|Ằ|Ẳ|Ẵ|Â|Ấ|Ầ|Ẩ|Ẫ|Ậ/',
19+
'/đ|Đ/',
20+
'/é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|É|È|Ẻ|Ẽ|Ẹ|Ê|Ế|Ề|Ể|Ễ|Ệ/',
21+
'/í|ì|ỉ|ĩ|ị|Í|Ì|Ỉ|Ĩ|Ị/',
22+
'/ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|Ó|Ò|Ỏ|Õ|Ọ|Ô|Ố|Ồ|Ổ|Ỗ|Ộ|Ơ|Ớ|Ờ|Ở|Ỡ|Ợ/',
23+
'/ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự|Ú|Ù|Ủ|Ũ|Ụ|Ư|Ứ|Ừ|Ử|Ữ|Ự/',
24+
'/ý|ỳ|ỷ|ỹ|ỵ|Ý|Ỳ|Ỷ|Ỹ|Ỵ/',
25+
);
26+
$to = array('a', 'd', 'e', 'i', 'o', 'u', 'y');
27+
28+
return preg_replace($from, $to, $string);
29+
}
30+
31+
public function userName()
32+
{
33+
$format = static::randomElement(static::$userNameFormats);
34+
35+
return static::toLower(static::toAscii(static::bothify($this->generator->parse($format))));
36+
}
37+
38+
public function domainWord()
39+
{
40+
$company = $this->generator->format('company');
41+
$companyElements = explode(' ', $company);
42+
$company = $companyElements[0];
43+
$company = preg_replace('/\W/u', '', $company);
44+
45+
return static::toLower(static::toAscii($company));
46+
}
47+
}

0 commit comments

Comments
 (0)