github 的文档中这样写:
Customization
Since you may want to make addresses and other types of data look different depending on where in the world you are (US postal codes vs. UK postal codes, for example), Faker uses the I18n gem to store strings (like state names) and formats (US postal codes are NNNNN while UK postal codes are AAN NAA), allowing you to get different formats by switching locales. Just set Faker::Config.locale to the locale you want, and Faker will take care of the rest.
If your locale doesn't already exist, create it in the \lib\locales\ directory and you can then override or add elements to suit
en-au-ocker: faker: name: # Existing faker field, new data first_name: [Charlotte, Ava, Chloe, Emily] # New faker fields ocker_first_name: [Bazza, Bluey, Davo, Johno, Shano, Shazza] region: [South East Queensland, Wide Bay Burnett, Margaret River, Port Pirie, Gippsland, Elizabeth, Barossa]
我在本地的 config/environments/test.rb 中加入了 Faker::Config.locale = 'zh-HK' 然后创建 lib/locales/zh-HK.yml 文件 zh-HK.yml 文件如下图 执行 rails console test 后
显示是 zh-HK,但是生成的 name 是英文的,不知道什么原因?