Skip to content

Commit d404b3b

Browse files
committed
chore: apply suggestions
1 parent 00a07b3 commit d404b3b

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

docs/guide/upgrading.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ Not the version you are looking for?
1616

1717
### Removed ability to change the locale on existing `Faker` instances
1818

19+
::: info NOTE
20+
If you are using only the default (`en`) instance, then you don't have to change anything.
21+
:::
22+
1923
In order to facilitate better and easier locale fallback mechanics, we removed the methods to change the locales on existing `Faker` instances.
2024
Now, we expose specific faker instances for each locale that you can use:
2125

@@ -39,35 +43,39 @@ This also fixes issues where more than two locales are required:
3943
**Old**
4044

4145
```ts
46+
import { faker } from '@faker-js/faker';
47+
4248
const customFaker = new Faker({
4349
locale: 'de_CH', // the expected locale
4450
fallbackLocale: 'de', // ensure we have a German fallbacks for addresses
4551
locales: { de_CH, de, en },
4652
});
47-
const a = customFaker.firstName();
53+
const a = customFaker.person.firstName();
4854
customFaker.locale = 'en'; // neither 'de_CH' nor 'de' have smileys
49-
const b = customFaker.smiley();
55+
const b = customFaker.internet.emoji();
5056
```
5157

5258
**New**
5359

5460
```ts
55-
import { Faker, de_CH, de, en } from '@faker-js/faker';
61+
import { Faker, de_CH, de, en, global } from '@faker-js/faker';
5662

5763
// same as fakerDE_CH
5864
export const customFaker = new Faker({
5965
// Now multiple fallbacks are supported
6066
locale: [customNames, customAddresses, de_CH, de, en, global],
6167
});
62-
const a = customFaker.firstName();
63-
const b = customFaker.smiley();
68+
const a = customFaker.person.firstName();
69+
const b = customFaker.internet.emoji();
6470
```
6571

6672
If you wish to create entries for multiple locales, you can still do so:
6773

6874
**Old**
6975

7076
```ts
77+
import { faker } from '@faker-js/faker';
78+
7179
for (let user of users) {
7280
const lang = faker.helpers.arrayElement(['de', 'en', 'fr']);
7381
faker.locale = lang;
@@ -78,6 +86,8 @@ for (let user of users) {
7886
**New**
7987

8088
```ts
89+
import { faker, fakerDE, fakerEN, fakerFR } from '@faker-js/faker';
90+
8191
for (let user of users) {
8292
const faker = faker.helpers.arrayElement([fakerDE, fakerEN, fakerFR]);
8393
user.name = faker.person.fullName();

0 commit comments

Comments
 (0)