Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(location): add list of spoken languages #3333

Merged
merged 32 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1baafaf
add list of spoken languages
UmairJibran Dec 10, 2024
5c2c6c7
remove dupes
UmairJibran Dec 10, 2024
f4c43b1
add language definition
UmairJibran Dec 10, 2024
97641de
add language module
UmairJibran Dec 10, 2024
8c2c997
add test case for `language()`
UmairJibran Dec 10, 2024
bd5872e
autogenerated supporting code
UmairJibran Dec 10, 2024
ddb348a
add languages for urdu
UmairJibran Dec 10, 2024
e7172b8
add test to make sure the values are truthy
UmairJibran Dec 11, 2024
191bdf8
update seed to match new format
UmairJibran Dec 11, 2024
220aefc
update language list
UmairJibran Dec 11, 2024
851e431
update documentation
UmairJibran Dec 11, 2024
b150a4a
update returns
UmairJibran Dec 11, 2024
3c9a494
language: convert alpha2 to lowercase
UmairJibran Dec 11, 2024
1c46263
update seed flies
UmairJibran Dec 11, 2024
f8d33fa
covert alpha3 to lowercase
UmairJibran Dec 11, 2024
204dde2
update seeders
UmairJibran Dec 11, 2024
ea6874a
update example
UmairJibran Dec 11, 2024
a4336c2
update version
UmairJibran Dec 11, 2024
8897dd3
use interface for language
UmairJibran Dec 11, 2024
72a18e9
Update index.ts
UmairJibran Dec 11, 2024
88211f7
Revert "Update index.ts"
UmairJibran Dec 11, 2024
62da737
Merge branch 'next' into next
UmairJibran Dec 11, 2024
403e1e0
Update src/modules/location/index.ts
UmairJibran Dec 12, 2024
47326c5
Update src/modules/location/index.ts
UmairJibran Dec 12, 2024
515450e
Update src/definitions/location.ts
UmairJibran Dec 12, 2024
24ac18f
language semantic
UmairJibran Dec 12, 2024
6852c42
add additional test cases
UmairJibran Dec 12, 2024
163be6c
add examples for each property
UmairJibran Dec 12, 2024
c9d8fb2
add languages for the supported locales
UmairJibran Dec 12, 2024
dc5f7fa
update seeds
UmairJibran Dec 12, 2024
92699e3
use example of german instead of english
UmairJibran Dec 13, 2024
347f203
Update src/definitions/location.ts
UmairJibran Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/definitions/location.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Language } from '../modules/location';
import type { LocaleEntry } from './definitions';

/**
Expand Down Expand Up @@ -147,4 +148,11 @@ export type LocationDefinition = LocaleEntry<{
* @see [IANA Time Zone Database](https://www.iana.org/time-zones)
*/
time_zone: string[];

/**
* A list of spoken languages.
*
* @see [ISO 639-2 Language Code List](https://www.loc.gov/standards/iso639-2/php/code_list.php)
*/
language: Language[];
}>;
2 changes: 2 additions & 0 deletions src/locales/en/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import continent from './continent';
import country from './country';
import county from './county';
import direction from './direction';
import language from './language';
import postcode from './postcode';
import secondary_address from './secondary_address';
import state from './state';
Expand All @@ -31,6 +32,7 @@ const location: LocationDefinition = {
country,
county,
direction,
language,
postcode,
secondary_address,
state,
Expand Down
73 changes: 73 additions & 0 deletions src/locales/en/location/language.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
export default [
{ name: 'Afrikaans', alpha2: 'af', alpha3: 'afr' },
{ name: 'Azerbaijani', alpha2: 'az', alpha3: 'aze' },
{ name: 'Maldivian', alpha2: 'dv', alpha3: 'div' },
{ name: 'Farsi/Persian', alpha2: 'fa', alpha3: 'fas' },
{ name: 'Latvian', alpha2: 'lv', alpha3: 'lav' },
{ name: 'Indonesian', alpha2: 'id', alpha3: 'ind' },
{ name: 'Nepali', alpha2: 'ne', alpha3: 'nep' },
{ name: 'Thai', alpha2: 'th', alpha3: 'tha' },
{ name: 'Uzbek', alpha2: 'uz', alpha3: 'uzb' },
{ name: 'Yoruba', alpha2: 'yo', alpha3: 'yor' },
{ name: 'Pashto', alpha2: 'ps', alpha3: 'pus' },
{ name: 'English', alpha2: 'en', alpha3: 'eng' },
{ name: 'Urdu', alpha2: 'ur', alpha3: 'urd' },
{ name: 'German', alpha2: 'de', alpha3: 'deu' },
{ name: 'French', alpha2: 'fr', alpha3: 'fra' },
{ name: 'Spanish', alpha2: 'es', alpha3: 'spa' },
{ name: 'Italian', alpha2: 'it', alpha3: 'ita' },
{ name: 'Dutch', alpha2: 'nl', alpha3: 'nld' },
{ name: 'Russian', alpha2: 'ru', alpha3: 'rus' },
{ name: 'Portuguese', alpha2: 'pt', alpha3: 'por' },
{ name: 'Polish', alpha2: 'pl', alpha3: 'pol' },
{ name: 'Arabic', alpha2: 'ar', alpha3: 'ara' },
{ name: 'Japanese', alpha2: 'ja', alpha3: 'jpn' },
{ name: 'Chinese', alpha2: 'zh', alpha3: 'zho' },
{ name: 'Hindi', alpha2: 'hi', alpha3: 'hin' },
{ name: 'Bengali', alpha2: 'bn', alpha3: 'ben' },
{ name: 'Gujarati', alpha2: 'gu', alpha3: 'guj' },
{ name: 'Tamil', alpha2: 'ta', alpha3: 'tam' },
{ name: 'Telugu', alpha2: 'te', alpha3: 'tel' },
{ name: 'Punjabi', alpha2: 'pa', alpha3: 'pan' },
{ name: 'Vietnamese', alpha2: 'vi', alpha3: 'vie' },
{ name: 'Korean', alpha2: 'ko', alpha3: 'kor' },
{ name: 'Turkish', alpha2: 'tr', alpha3: 'tur' },
{ name: 'Swedish', alpha2: 'sv', alpha3: 'swe' },
{ name: 'Greek', alpha2: 'el', alpha3: 'ell' },
{ name: 'Czech', alpha2: 'cs', alpha3: 'ces' },
{ name: 'Hungarian', alpha2: 'hu', alpha3: 'hun' },
{ name: 'Romanian', alpha2: 'ro', alpha3: 'ron' },
{ name: 'Ukrainian', alpha2: 'uk', alpha3: 'ukr' },
{ name: 'Norwegian', alpha2: 'no', alpha3: 'nor' },
{ name: 'Serbian', alpha2: 'sr', alpha3: 'srp' },
{ name: 'Croatian', alpha2: 'hr', alpha3: 'hrv' },
{ name: 'Slovak', alpha2: 'sk', alpha3: 'slk' },
{ name: 'Slovenian', alpha2: 'sl', alpha3: 'slv' },
{ name: 'Icelandic', alpha2: 'is', alpha3: 'isl' },
{ name: 'Finnish', alpha2: 'fi', alpha3: 'fin' },
{ name: 'Danish', alpha2: 'da', alpha3: 'dan' },
{ name: 'Swahili', alpha2: 'sw', alpha3: 'swa' },
{ name: 'Bashkir', alpha2: 'ba', alpha3: 'bak' },
{ name: 'Basque', alpha2: 'eu', alpha3: 'eus' },
{ name: 'Catalan', alpha2: 'ca', alpha3: 'cat' },
{ name: 'Galician', alpha2: 'gl', alpha3: 'glg' },
{ name: 'Esperanto', alpha2: 'eo', alpha3: 'epo' },
{ name: 'Fijian', alpha2: 'fj', alpha3: 'fij' },
{ name: 'Malagasy', alpha2: 'mg', alpha3: 'mlg' },
{ name: 'Maltese', alpha2: 'mt', alpha3: 'mlt' },
{ name: 'Albanian', alpha2: 'sq', alpha3: 'sqi' },
{ name: 'Armenian', alpha2: 'hy', alpha3: 'hye' },
{ name: 'Georgian', alpha2: 'ka', alpha3: 'kat' },
{ name: 'Macedonian', alpha2: 'mk', alpha3: 'mkd' },
{ name: 'Kazakh', alpha2: 'kk', alpha3: 'kaz' },
{ name: 'Haitian Creole', alpha2: 'ht', alpha3: 'hat' },
{ name: 'Mongolian', alpha2: 'mn', alpha3: 'mon' },
{ name: 'Kyrgyz', alpha2: 'ky', alpha3: 'kir' },
{ name: 'Finnish', alpha2: 'fi', alpha3: 'fin' },
{ name: 'Tagalog', alpha2: 'tl', alpha3: 'tgl' },
{ name: 'Malay', alpha2: 'ms', alpha3: 'msa' },
{ name: 'Tajik', alpha2: 'tg', alpha3: 'tgk' },
{ name: 'Swati', alpha2: 'ss', alpha3: 'ssw' },
{ name: 'Tatar', alpha2: 'tt', alpha3: 'tat' },
{ name: 'Zulu', alpha2: 'zu', alpha3: 'zul' },
];
2 changes: 2 additions & 0 deletions src/locales/ur/location/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import city_prefix from './city_prefix';
import city_suffix from './city_suffix';
import country from './country';
import direction from './direction';
import language from './language';
import postcode from './postcode';
import secondary_address from './secondary_address';
import state from './state';
Expand All @@ -26,6 +27,7 @@ const location: LocationDefinition = {
city_suffix,
country,
direction,
language,
postcode,
secondary_address,
state,
Expand Down
33 changes: 33 additions & 0 deletions src/locales/ur/location/language.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export default [
{ name: 'پشتو', alpha2: 'ps', alpha3: 'pus' },
{ name: 'اردو', alpha2: 'ur', alpha3: 'urd' },
{ name: 'انگریزی', alpha2: 'en', alpha3: 'eng' },
{ name: 'جرمن', alpha2: 'de', alpha3: 'deu' },
{ name: 'فرانسیسی', alpha2: 'fr', alpha3: 'fra' },
{ name: 'اسپینش', alpha2: 'es', alpha3: 'spa' },
{ name: 'دچ', alpha2: 'nl', alpha3: 'nld' },
{ name: 'روسی', alpha2: 'ru', alpha3: 'rus' },
{ name: 'پرتگالی', alpha2: 'pt', alpha3: 'por' },
{ name: 'پولش', alpha2: 'pl', alpha3: 'pol' },
{ name: 'عربی', alpha2: 'ar', alpha3: 'ara' },
{ name: 'جاپانی', alpha2: 'ja', alpha3: 'jpn' },
{ name: 'چینی', alpha2: 'zh', alpha3: 'zho' },
{ name: 'ہندی', alpha2: 'hi', alpha3: 'hin' },
{ name: 'بنگالی', alpha2: 'bn', alpha3: 'ben' },
{ name: 'تمل', alpha2: 'ta', alpha3: 'tam' },
{ name: 'تلگو', alpha2: 'te', alpha3: 'tel' },
{ name: 'پنجابی', alpha2: 'pa', alpha3: 'pan' },
{ name: 'ترکی', alpha2: 'tr', alpha3: 'tur' },
{ name: 'سویڈش', alpha2: 'sv', alpha3: 'swe' },
{ name: 'یونانی', alpha2: 'el', alpha3: 'ell' },
{ name: 'چیک', alpha2: 'cs', alpha3: 'ces' },
{ name: 'ہنگرین', alpha2: 'hu', alpha3: 'hun' },
{ name: 'نارویجن', alpha2: 'no', alpha3: 'nor' },
{ name: 'کروشیائی', alpha2: 'hr', alpha3: 'hrv' },
{ name: 'سلوواک', alpha2: 'sk', alpha3: 'slk' },
{ name: 'سلووینیائی', alpha2: 'sl', alpha3: 'slv' },
{ name: 'فنش', alpha2: 'fi', alpha3: 'fin' },
{ name: 'دنش', alpha2: 'da', alpha3: 'dan' },
{ name: 'مالٹی', alpha2: 'mt', alpha3: 'mlt' },
{ name: 'تاجک', alpha2: 'tg', alpha3: 'tgk' },
];
41 changes: 41 additions & 0 deletions src/modules/location/index.ts
Original file line number Diff line number Diff line change
@@ -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`.
*
Expand Down Expand Up @@ -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
);
}
}
24 changes: 24 additions & 0 deletions test/modules/__snapshots__/location.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ exports[`location > 42 > direction > noArgs 1`] = `"South"`;

exports[`location > 42 > direction > with abbreviated option 1`] = `"S"`;

exports[`location > 42 > language 1`] = `
{
"alpha2": "gu",
"alpha3": "guj",
"name": "Gujarati",
}
`;

exports[`location > 42 > latitude > noArgs 1`] = `-22.5828`;

exports[`location > 42 > latitude > with max and min option 1`] = `-2.5092`;
Expand Down Expand Up @@ -170,6 +178,14 @@ exports[`location > 1211 > direction > noArgs 1`] = `"Southwest"`;

exports[`location > 1211 > direction > with abbreviated option 1`] = `"SW"`;

exports[`location > 1211 > language 1`] = `
{
"alpha2": "tl",
"alpha3": "tgl",
"name": "Tagalog",
}
`;

exports[`location > 1211 > latitude > noArgs 1`] = `77.1337`;

exports[`location > 1211 > latitude > with max and min option 1`] = `8.5704`;
Expand Down Expand Up @@ -308,6 +324,14 @@ exports[`location > 1337 > direction > noArgs 1`] = `"South"`;

exports[`location > 1337 > direction > with abbreviated option 1`] = `"S"`;

exports[`location > 1337 > language 1`] = `
{
"alpha2": "ru",
"alpha3": "rus",
"name": "Russian",
}
`;

exports[`location > 1337 > latitude > noArgs 1`] = `-42.8356`;

exports[`location > 1337 > latitude > with max and min option 1`] = `-4.7595`;
Expand Down
15 changes: 15 additions & 0 deletions test/modules/location.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ describe('location', () => {

t.it('timeZone');

t.it('language');

t.describeEach(
'direction',
'cardinalDirection',
Expand Down Expand Up @@ -415,6 +417,19 @@ describe('location', () => {
expect(faker.definitions.location.time_zone).toContain(actual);
});
});

describe('language()', () => {
it('should return a random language', () => {
const actual = faker.location.language();
expect(actual.name).toBeTruthy();
expect(actual.alpha2).toBeTruthy();
UmairJibran marked this conversation as resolved.
Show resolved Hide resolved
expect(actual.alpha2).toHaveLength(2);
expect(actual.alpha3).toBeTruthy();
expect(actual.alpha3).toHaveLength(3);

expect(faker.definitions.location.language).toContain(actual);
});
});
}
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ exports[`check docs completeness > all modules and methods are present 1`] = `
"countryCode",
"county",
"direction",
"language",
"latitude",
"longitude",
"nearbyGPSCoordinate",
Expand Down
Loading