From ff6dda94ddd312ebcff816cbb63e74df9857d091 Mon Sep 17 00:00:00 2001 From: Umair Jibran Date: Sat, 14 Dec 2024 16:00:59 +0500 Subject: feat(location): add list of spoken languages (#3333) * add list of spoken languages * remove dupes * add language definition * add language module * add test case for `language()` * autogenerated supporting code * add languages for urdu * add test to make sure the values are truthy * update seed to match new format * update language list slim them down to a few languages as the long list was not easy to build up * update documentation * update returns * language: convert alpha2 to lowercase * update seed flies * covert alpha3 to lowercase * update seeders * update example * update version * use interface for language * Update index.ts * Revert "Update index.ts" This reverts commit 72a18e99cfee1f4c09d151b27bda1f2c8d1137d8. * Update src/modules/location/index.ts Co-authored-by: ST-DDT * Update src/modules/location/index.ts Co-authored-by: ST-DDT * Update src/definitions/location.ts Co-authored-by: ST-DDT * language semantic Co-authored-by: ST-DDT * add additional test cases * add examples for each property * add languages for the supported locales * update seeds * use example of german instead of english * Update src/definitions/location.ts Co-authored-by: ST-DDT --------- Co-authored-by: ST-DDT --- src/modules/location/index.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/modules') diff --git a/src/modules/location/index.ts b/src/modules/location/index.ts index 4a49e029..29267eb1 100644 --- a/src/modules/location/index.ts +++ b/src/modules/location/index.ts @@ -1,6 +1,26 @@ import { FakerError } from '../../errors/faker-error'; import { ModuleBase } from '../../internal/module-base'; +/** + * Represents a language with its full name, 2 character ISO 639-1 code, and 3 character ISO 639-2 code. + */ +export interface Language { + /** + * The full name for the language (e.g. `English`). + */ + name: string; + + /** + * The 2 character [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) code. + */ + alpha2: string; + + /** + * The 3 character [ISO 639-2](https://en.wikipedia.org/wiki/ISO_639-2) code. + */ + alpha3: string; +} + /** * Module to generate addresses and locations. Prior to Faker 8.0.0, this module was known as `faker.address`. * @@ -628,4 +648,25 @@ export class LocationModule extends ModuleBase { this.faker.definitions.location.time_zone ); } + + /** + * Returns a random spoken language. + * + * @see [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) + * @see [ISO 639-2](https://en.wikipedia.org/wiki/ISO_639-2) + * @see [ISO 639-2 Language Code List](https://www.loc.gov/standards/iso639-2/php/code_list.php) + * + * @example + * faker.location.language() // { alpha2: 'de', alpha3: 'deu', name: 'German' } + * faker.location.language().name // German + * faker.location.language().alpha2 // de + * faker.location.language().alpha3 // deu + * + * @since 9.4.0 + */ + language(): Language { + return this.faker.helpers.arrayElement( + this.faker.definitions.location.language + ); + } } -- cgit v1.2.3