Permalink
Browse files

Merge pull request #53 from blaugueux/locale

Added locale generator to Internet provider.
  • Loading branch information...
2 parents a3636d7 + 4acfeb7 commit cc2a254a5c49cb9c91ce41c5e195040809077765 @fzaninotto committed Oct 7, 2012
Showing with 28 additions and 0 deletions.
  1. +3 −0 readme.md
  2. +25 −0 src/Faker/Provider/Miscellaneous.php
View
@@ -150,6 +150,9 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle
md5 // 'de99a620c50f2990e87144735cd357e7'
sha1 // 'f08e7f04ca1a413807ebc47551a40a20a0b4de5c'
sha256 // '0061e4c60dac5c1d82db0135a42e00c89ae3a333e7c26485321f24348c7e98a5'
+ locale // en_UK
+ countryCode // UK
+ languageCode // en
### `Faker\Provider\Base`
@@ -4,7 +4,9 @@
class Miscellaneous extends \Faker\Provider\Base
{
+ protected static $languageCode = array('cn', 'de', 'en', 'es', 'fr', 'it', 'pt', 'ru');
+ protected static $countryCode = array('CA', 'CN', 'DE', 'ES', 'FR', 'IE', 'IN', 'IT', 'MX', 'PT', 'RU', 'UK', 'US');
/**
* Return a boolean, true or false
*
@@ -39,5 +41,28 @@ public static function sha256()
{
return hash('sha256', mt_rand());
}
+
+ /**
+ * @example 'fr_FR'
+ */
+ public function locale()
+ {
+ return $this->languageCode() . '_' . $this->countryCode();
+ }
+ /**
+ * @example 'FR'
+ */
+ public static function countryCode()
+ {
+ return static::randomElement(static::$countryCode);
+ }
+
+ /**
+ * @example 'fr'
+ */
+ public static function languageCode()
+ {
+ return static::randomElement(static::$languageCode);
+ }
}

0 comments on commit cc2a254

Please sign in to comment.