diff options
| author | Umair Jibran <[email protected]> | 2024-12-14 16:00:59 +0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-12-14 11:00:59 +0000 |
| commit | ff6dda94ddd312ebcff816cbb63e74df9857d091 (patch) | |
| tree | 6c4e9541d330dabdf739d4c1e6d3757a2dc42f78 /src/modules/location | |
| parent | 3c7abb55e68fcbcf41560539a15845e7c8882765 (diff) | |
| download | faker-ff6dda94ddd312ebcff816cbb63e74df9857d091.tar.xz faker-ff6dda94ddd312ebcff816cbb63e74df9857d091.zip | |
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 <[email protected]>
* Update src/modules/location/index.ts
Co-authored-by: ST-DDT <[email protected]>
* Update src/definitions/location.ts
Co-authored-by: ST-DDT <[email protected]>
* language semantic
Co-authored-by: ST-DDT <[email protected]>
* 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 <[email protected]>
---------
Co-authored-by: ST-DDT <[email protected]>
Diffstat (limited to 'src/modules/location')
| -rw-r--r-- | src/modules/location/index.ts | 41 |
1 files changed, 41 insertions, 0 deletions
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 @@ -2,6 +2,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`. * * ### Overview @@ -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 + ); + } } |
