Change locale during runtime #1049
Replies: 4 comments 6 replies
-
I'd voted yes as I remembered using the locale function for storybook stories. Our app is in 18 languages so it is helpful for mocking user data in the correct language. Though after I voted I realised that as long as we could still use multiple locales at the same time we wouldn't need the dynamic locale switching. Something like |
Beta Was this translation helpful? Give feedback.
-
Yeah so long as a dynamic import can serve the additional locales on demand, ripping it out by default would be A++. |
Beta Was this translation helpful? Give feedback.
-
If we keep supporting dynamic switching (#642), things like this would be possible: import { faker } from '@faker/faker-js' // faker logic
import { de } from '@faker/faker-js/locales/de' // only definitions
faker.locale = de
faker.firstName()
faker.locale = null
faker.firstName() // en
|
Beta Was this translation helpful? Give feedback.
-
Another interesting concept is having the ability to generate random data across multiple locales randomly. Idea (stolen from https://github.com/joke2k/faker#localization): import { faker } from '@faker/faker-js' // faker logic
import { en } from '@faker/faker-js/locales/en' // only definitions
import { it } from '@faker/faker-js/locales/it' // only definitions
import { jp } from '@faker/faker-js/locales/jp' // only definitions
faker.locales = [it, en, jp]
for (const i = 0; i < 10; i++) {
console.log(faker.name.fullName())
}
// 鈴木 陽一
// Leslie Moreno
// Emma Williams
// 渡辺 裕美子
// Marcantonio Galuppi
// Martha Davis
// Kristen Turner
// 中津川 春香
// Ashley Castillo
// 山田 桃子 Would anybody need this? |
Beta Was this translation helpful? Give feedback.
-
Localization is a hard topic. But to make data as individual as possible, Faker provides many locales you can choose from for your data generation.
But changing the locale during runtime makes a lot of trouble for the faker-js team. And we couldn't come up with a real use case for this. So we discussed a possible solution and came to the conclusion of dropping local changes during runtime and instead need to provide them during Faker instance initialization.
Our library wouldn't be the same without YOU (our community), so we would like your feedback on our proposal.
28 votes ·
Beta Was this translation helpful? Give feedback.
All reactions