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

refactor(locale)!: remove unused separator entry #1731

Merged
merged 6 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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: 2 additions & 6 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
let localeDef: LocaleDefinition;
// This call might fail, if the module setup is broken.
// Unfortunately, we try to fix it with this script
// Thats why have a fallback logic here, we only need the title and separator anyway
// Thats why have a fallback logic here, we only need the title anyway
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
localeDef = require(pathModules).default;
Expand All @@ -147,7 +147,6 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
);
localeDef = {
title: localeIndex.match(/title: '(.*)',/)[1],
separator: localeIndex.match(/separator: '(.*)',/)?.[1],
};
} catch {
console.error(`Failed to load ${pathModules} or manually parse it.`, e);
Expand Down Expand Up @@ -287,7 +286,6 @@ for (const locale of locales) {
const localeDef = tryLoadLocalesMainIndexFile(pathModules);
// We use a fallback here to at least generate a working file.
const localeTitle = localeDef?.title ?? `TODO: Insert Title for ${locale}`;
const localeSeparator = localeDef?.separator;

localeIndexImports += `import ${locale} from './${locale}';\n`;
localeIndexType += ` | '${locale}'\n`;
Expand All @@ -298,14 +296,12 @@ for (const locale of locales) {
generateLocaleFile(locale);

// src/locales/**/index.ts
const separator = localeSeparator ? `\nseparator: '${localeSeparator}',` : '';

generateRecursiveModuleIndexes(
pathModules,
locale,
'LocaleDefinition',
1,
`title: '${localeTitle}',${separator}`
`title: '${localeTitle}',`
);
}

Expand Down
1 change: 0 additions & 1 deletion src/definitions/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ export type LocaleDefinition = {
* The name of the language.
*/
title: string;
separator?: string;
} & LocaleEntry<Definitions>;
5 changes: 1 addition & 4 deletions src/faker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export interface FakerOptions {
localeFallback?: UsableLocale;
}

const metadataKeys: ReadonlyArray<keyof LocaleDefinition> = [
'title',
'separator',
];
const metadataKeys: ReadonlyArray<keyof LocaleDefinition> = ['title'];

export class Faker {
locales: UsedLocales;
Expand Down
1 change: 0 additions & 1 deletion src/locales/ar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import vehicle from './vehicle';

const ar: LocaleDefinition = {
title: 'Arabic',
separator: ' & ',
cell_phone,
color,
commerce,
Expand Down
1 change: 0 additions & 1 deletion src/locales/az/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import phone_number from './phone_number';

const az: LocaleDefinition = {
title: 'Azerbaijani',
separator: ' və ',
color,
commerce,
company,
Expand Down
1 change: 0 additions & 1 deletion src/locales/el/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import team from './team';

const el: LocaleDefinition = {
title: 'Greek',
separator: ' & ',
app,
business,
cell_phone,
Expand Down
1 change: 0 additions & 1 deletion src/locales/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import word from './word';

const en: LocaleDefinition = {
title: 'English',
separator: ' & ',
animal,
app,
business,
Expand Down
1 change: 0 additions & 1 deletion src/locales/es_MX/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import team from './team';

const es_MX: LocaleDefinition = {
title: 'Spanish (Mexico)',
separator: ' & ',
cell_phone,
color,
commerce,
Expand Down
1 change: 0 additions & 1 deletion src/locales/ge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import phone_number from './phone_number';

const ge: LocaleDefinition = {
title: 'Georgian',
separator: ' და ',
cell_phone,
company,
internet,
Expand Down
1 change: 0 additions & 1 deletion src/locales/he/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import phone_number from './phone_number';

const he: LocaleDefinition = {
title: 'Hebrew',
separator: 'ו ',
cell_phone,
color,
commerce,
Expand Down
1 change: 0 additions & 1 deletion src/locales/hy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import phone_number from './phone_number';

const hy: LocaleDefinition = {
title: 'Armenian',
separator: ' և ',
color,
date,
internet,
Expand Down
1 change: 0 additions & 1 deletion src/locales/lv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import phone_number from './phone_number';

const lv: LocaleDefinition = {
title: 'Latvian',
separator: ' un ',
cell_phone,
color,
commerce,
Expand Down
1 change: 0 additions & 1 deletion src/locales/mk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import phone_number from './phone_number';

const mk: LocaleDefinition = {
title: 'Macedonian',
separator: ' и ',
cell_phone,
company,
date,
Expand Down
1 change: 0 additions & 1 deletion src/locales/ru/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import phone_number from './phone_number';

const ru: LocaleDefinition = {
title: 'Russian',
separator: ' и ',
color,
commerce,
company,
Expand Down
1 change: 0 additions & 1 deletion src/locales/ur/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import vehicle from './vehicle';

const ur: LocaleDefinition = {
title: 'Urdu',
separator: ' اور ',
animal,
app,
business,
Expand Down
14 changes: 0 additions & 14 deletions test/faker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ describe('faker', () => {
});
});

describe('separator', () => {
it.each(Object.keys(faker.locales))('separator (%s)', (locale) => {
faker.locale = locale;
expect(faker.definitions.separator).toBeTypeOf('string');
});

it('separator (with fallback)', () => {
// Use a language that doesn't have a separator specified
expect(faker.locales['en_US'].separator).toBeUndefined();
// Check that the fallback works
expect(faker.definitions.separator).toBe(faker.locales['en'].separator);
});
});

it('locale definition accessability', () => {
// Metadata
expect(faker.definitions.title).toBeDefined();
Expand Down