aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/guide/localization.md4
-rw-r--r--src/faker.ts5
-rw-r--r--src/internal/locale-proxy.ts1
-rw-r--r--test/internal/locale-proxy.spec.ts2
-rw-r--r--test/modules/location.spec.ts1
5 files changed, 10 insertions, 3 deletions
diff --git a/docs/guide/localization.md b/docs/guide/localization.md
index f40a2f48..b548d523 100644
--- a/docs/guide/localization.md
+++ b/docs/guide/localization.md
@@ -181,11 +181,11 @@ As a workaround, you can provide additional fallbacks to your `Faker` instance:
```ts
import { Faker, el } from '@faker-js/faker'; // [!code --]
-import { Faker, el, en } from '@faker-js/faker'; // [!code ++]
+import { Faker, base, el, en } from '@faker-js/faker'; // [!code ++]
const faker = new Faker({
locale: [el], // [!code --]
- locale: [el, en], // [!code ++]
+ locale: [el, en, base], // [!code ++]
});
console.log(faker.location.country()); // 'Belgium'
```
diff --git a/src/faker.ts b/src/faker.ts
index 0b03788b..d9e9905b 100644
--- a/src/faker.ts
+++ b/src/faker.ts
@@ -120,7 +120,9 @@ export class Faker extends SimpleFaker {
* For more information see our [Localization Guide](https://fakerjs.dev/guide/localization.html).
*
* @param options The options to use.
- * @param options.locale The locale data to use.
+ * @param options.locale The locale data to use for this instance.
+ * If an array is provided, the first locale that has a definition for a given property will be used.
+ * Please make sure that all required locales and their parent locales are present, e.g. `[de_AT, de, en, base]`.
* @param options.randomizer The Randomizer to use.
* Specify this only if you want to use it to achieve a specific goal,
* such as sharing the same random generator with other instances/tools.
@@ -148,6 +150,7 @@ export class Faker extends SimpleFaker {
/**
* The locale data to use for this instance.
* If an array is provided, the first locale that has a definition for a given property will be used.
+ * Please make sure that all required locales and their parent locales are present, e.g. `[de_AT, de, en, base]`.
*
* @see mergeLocales(): For more information about how the locales are merged.
*/
diff --git a/src/internal/locale-proxy.ts b/src/internal/locale-proxy.ts
index dbb9f277..3e77a93a 100644
--- a/src/internal/locale-proxy.ts
+++ b/src/internal/locale-proxy.ts
@@ -72,6 +72,7 @@ export function assertLocaleData<T>(
} else if (value === undefined) {
throw new FakerError(
`The locale data for '${path.join('.')}' are missing in this locale.
+ If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://fakerjs.dev/guide/localization.html`
);
diff --git a/test/internal/locale-proxy.spec.ts b/test/internal/locale-proxy.spec.ts
index 1b6e060b..133e7084 100644
--- a/test/internal/locale-proxy.spec.ts
+++ b/test/internal/locale-proxy.spec.ts
@@ -97,6 +97,7 @@ describe('LocaleProxy', () => {
expect(() => locale.category.missing).toThrow(
new FakerError(
`The locale data for 'category.missing' are missing in this locale.
+ If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://fakerjs.dev/guide/localization.html`
)
@@ -107,6 +108,7 @@ describe('LocaleProxy', () => {
expect(() => locale.airline.missing).toThrow(
new FakerError(
`The locale data for 'airline.missing' are missing in this locale.
+ If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://fakerjs.dev/guide/localization.html`
)
diff --git a/test/modules/location.spec.ts b/test/modules/location.spec.ts
index 78b68812..8af00f37 100644
--- a/test/modules/location.spec.ts
+++ b/test/modules/location.spec.ts
@@ -220,6 +220,7 @@ describe('location', () => {
expect(() => faker.location.zipCode({ state: 'XX' })).toThrow(
new FakerError(
`The locale data for 'location.postcode_by_state' are missing in this locale.
+ If this is a custom Faker instance, please make sure all required locales are used e.g. '[de_AT, de, en, base]'.
Please contribute the missing data to the project or use a locale/Faker instance that has these data.
For more information see https://fakerjs.dev/guide/localization.html`
)