Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
en Change Faker::Lorem.multibyte logic (#1317) Aug 16, 2018
README.md Add documentation for locales Jul 12, 2017
bg.yml Added bg locale (#858) Mar 23, 2017
ca-CAT.yml Replace all char-160 to char-32 (#1165) Mar 26, 2018
ca.yml Adds first_name Jan 30, 2016
da-DK.yml Adding country code + minor locale updates (#794) May 20, 2018
de-AT.yml Adding country code + minor locale updates (#794) May 20, 2018
de-CH.yml Update i18n and use correct locales Jul 3, 2014
de.yml add german commerce translations (#616) Jun 19, 2018
ee.yml Add Faker::SouthAfrica (#1324) Aug 5, 2018
en-AU.yml Add AU mobile-phone formats Sep 3, 2015
en-BORK.yml Update i18n and use correct locales Jul 3, 2014
en-CA.yml Add area and exchange code features for en-CA Dec 25, 2017
en-GB.yml Adding country code + minor locale updates (#794) May 20, 2018
en-IND.yml Add city to en-IND locale and add test for en-IND city Mar 27, 2017
en-MS.yml Add Malaysia's commercials and islamics bank (#1045) Oct 13, 2017
en-NEP.yml Added default_timezone/default_country_code and updated postcode for … Jul 21, 2015
en-NG.yml Add Nigerian locale Sep 8, 2016
en-NZ.yml Adding country code + minor locale updates (#794) May 20, 2018
en-PAK.yml Added en-PAK locale Jun 20, 2016
en-SG.yml s/prefix/english_name Feb 24, 2015
en-UG.yml Fixed spec errors Jul 18, 2015
en-US.yml Adding country code + minor locale updates (#794) May 20, 2018
en-ZA.yml Add Faker::SouthAfrica (#1324) Aug 5, 2018
en-au-ocker.yml Add AU mobile-phone formats Sep 3, 2015
en.yml Change Faker::Lorem.multibyte logic (#1317) Aug 16, 2018
es-MX.yml ex-MX.yml: city_prefix and city_suffix: replace empty list with empty… Dec 19, 2016
es.yml Add gender to name generator (#551) Jun 26, 2018
fa.yml Add farsi ( persian ) name prefix Feb 25, 2014
fi-FI.yml Add Faker::Invoice to generate valid bank slip references (#1050) Jun 11, 2018
fr-CA.yml Add fr_CA locale (#1262) Jun 5, 2018
fr-CH.yml Add fr_CH locale (#1261) Jun 5, 2018
fr.yml Adding country code + minor locale updates (#794) May 20, 2018
he.yml Add Hebrew locale file Dec 28, 2014
id.yml Add indonesian locale (#730) Dec 17, 2016
it.yml Adding country code + minor locale updates (#794) May 20, 2018
ja.yml Add Japanese lorem words to locale (#900) May 21, 2018
ko.yml change korean postcode format (#1058) Nov 18, 2017
lv.yml Add Estonian and Latvian locales (#1140) May 27, 2018
nb-NO.yml Merge pull request #265 from helgeblod/master Oct 30, 2015
nl.yml Fixes NL postcode (#1197) May 12, 2018
no.yml Add Faker::Invoice to generate valid bank slip references (#1050) Jun 11, 2018
pl.yml Adding country code + minor locale updates (#794) May 20, 2018
pt-BR.yml Faker::Vehicle API updates (#1130) Aug 15, 2018
pt.yml Adding country code + minor locale updates (#794) May 20, 2018
ru.yml Fix first names in Russian locale (#1025) Oct 12, 2017
sk.yml Added state and state_abbr to sk.yml Aug 25, 2015
sv.yml Update list of name prefixes for sv locale (#1249) May 25, 2018
tr.yml Adds turkish phone number formats and test. (#1106) May 22, 2018
uk.yml Added Ukrainian entries to yml (#1117) May 20, 2018
vi.yml Add Commerce color and product name Apr 1, 2013
zh-CN.yml Updates to zh-CN locale Jul 12, 2017
zh-TW.yml add zh-TW locale Jan 29, 2015

README.md

How Locales Work

The default locale is English. You can see how it is implemented in the "translate" method in Faker.rb.

Here's how to set it:

# Sets the locale to "Simplified Chinese":

Faker::Config.locale = 'zh-CN'

It works so that once the Faker locale is set to a different location, the translate method will check that .yml file for an equivalent and use that data. If it doesn't exist, it defaults back to English. It uses the "i18n" gem to do this.

Using Chinese as an example, when the locale is set to Chinese and you attempt to call for hipster ipsem (which doesn't exist at the time of this writing), you will get English back. It checks the "zh-CH.yml" file, does not find "hipster" and then checks the "en.yml" file and returns a word from that array.

Faker::Config.locale = 'zh-CN'

Faker::Hipster.word #=> "kogi"

In order to update a locale with more translation features, simply add a new field to the .yml file that corresponds to an existing piece of functionality in the "en.yml" file. In this example, that would mean providing Chinese hipster words.

# /lib/locales/zh-CN.yml

hipster: ["屌丝"]

# Now this should work:

Faker::Hipster.word #=> "屌丝"

After you've done that, find or create a test file for the locale you've updated and test the functionality for that language.

In our hypothetical example here, one would add something like this to the "test-zh-locale.rb" file in the "test_ch_methods" method:

assert Faker::Hipster.word.is_a? String