faker-js / faker

Generate massive amounts of fake data in the browser and node.js
https://fakerjs.dev
Other
13.03k stars 919 forks source link

'lorem.words' missing for zh_CN #2907

Open oofdie opened 6 months ago

oofdie commented 6 months ago

Pre-Checks

Describe the bug

@faker-js/faker@8.4.1 const customFaker = new Faker({ locale: [zh_CN] }); customFaker.lorem.paragraphs({ min:2, max:3 }, '\n') get error "The locale data for 'lorem.words' are missing in this locale. Please contribute the missing data to the project or use a locale/Faker instance that has these data."

Minimal reproduction code

No response

Additional Context

image

Environment Info

System:
    OS: macOS 13.0
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 112.32 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.20.2 - ~/.nvm/versions/node/v16.20.2/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 8.19.4 - ~/.nvm/versions/node/v16.20.2/bin/npm
    pnpm: 7.33.7 - ~/.nvm/versions/node/v16.20.2/bin/pnpm
  Browsers:
    Chrome: 124.0.6367.209
    Safari: 16.1
  npmPackages:
    @faker-js/faker: ^8.4.1 => 8.4.1

Which module system do you use?

Used Package Manager

pnpm

ST-DDT commented 6 months ago

What do you expect for lorem data in zh_CN? Chinese words or latin words?

Ref:

Workaround:

new Faker({ locale: [zh_CN, {lorem: en.lorem}]});
// or
new Faker({ locale: [zh_CN, en]});
// or
new Faker({ locale: [zh_CN, {lorem: {words: zh_CN.word.noun }}]});
oofdie commented 6 months ago

What I expected was to get pure Chinese words. Adding 'en' to the locale indeed solves the error, because Faker automatically generates paragraphs in all English words.

new Faker({ locale: [zh_CN, {lorem: en.lorem}]});  // All English words
// or
new Faker({ locale: [zh_CN, en]}); // All English words
// or
new Faker({ locale: [zh_CN, {lorem: {words: zh_CN.word.noun }}]});  // The locale data for 'lorem.words' are missing in this locale
ST-DDT commented 6 months ago

Sorry I didn't notice that zh_CN doesn't have nouns.

new Faker({ locale: [zh_CN, { lorem: { words: zh_CN.word.verb } }] }); // 写 驾驶 拎 拧 捡 舞. 抚 跳 拿 托 挡 坐 吮 抬 擦 搔. 擦 抛 披.

Is this what you expect?

FFR: en lorem = Latin

matthewmayer commented 6 months ago

Chinese doesn't normally put spaces in between words. My feeling is that "Chinese" lorem equivalent would be a long string of real Chinese characters but with nonsense meanings, not necessarily real words.

oofdie commented 6 months ago

Thank you @ST-DDT, your solution indeed solves my problem. It outputs continuous Chinese paragraphs, but they are interspersed with spaces which I need to handle myself. The reason I raised this issue is that I didn't find a similar solution in the demos on the documentation. I hope that in the future, the faker team can include such cases in the documentation or provide better support for Chinese, just like in the demos.

const customFaker = new Faker({
local: [zh_CN]
})
customFaker.lorem.paragraphs({ min: 2, max: 5 }, '\n')
ST-DDT commented 1 month ago

Blocked by: