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(types): rename locale definition types to singular #2058

Merged
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
52 changes: 26 additions & 26 deletions scripts/generateLocales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { resolve } from 'node:path';
import type { Options } from 'prettier';
import { format } from 'prettier';
import options from '../.prettierrc.cjs';
import type { LocaleDefinition, MetadataDefinitions } from '../src/definitions';
import type { LocaleDefinition, MetadataDefinition } from '../src/definitions';

// Constants

Expand All @@ -44,34 +44,34 @@ type PascalCase<S extends string> = S extends `${infer P1}_${infer P2}`
? `${Capitalize<P1>}${PascalCase<P2>}`
: Capitalize<S>;

type DefinitionsType = {
[key in keyof LocaleDefinition]-?: PascalCase<`${key}Definitions`>;
type DefinitionType = {
[key in keyof LocaleDefinition]-?: PascalCase<`${key}Definition`>;
};

/**
* The types of the definitions.
*/
const definitionsTypes: DefinitionsType = {
airline: 'AirlineDefinitions',
animal: 'AnimalDefinitions',
color: 'ColorDefinitions',
commerce: 'CommerceDefinitions',
company: 'CompanyDefinitions',
database: 'DatabaseDefinitions',
date: 'DateDefinitions',
finance: 'FinanceDefinitions',
hacker: 'HackerDefinitions',
internet: 'InternetDefinitions',
location: 'LocationDefinitions',
lorem: 'LoremDefinitions',
metadata: 'MetadataDefinitions',
music: 'MusicDefinitions',
person: 'PersonDefinitions',
phone_number: 'PhoneNumberDefinitions',
science: 'ScienceDefinitions',
system: 'SystemDefinitions',
vehicle: 'VehicleDefinitions',
word: 'WordDefinitions',
const definitionsTypes: DefinitionType = {
airline: 'AirlineDefinition',
animal: 'AnimalDefinition',
color: 'ColorDefinition',
commerce: 'CommerceDefinition',
company: 'CompanyDefinition',
database: 'DatabaseDefinition',
date: 'DateDefinition',
finance: 'FinanceDefinition',
hacker: 'HackerDefinition',
internet: 'InternetDefinition',
location: 'LocationDefinition',
lorem: 'LoremDefinition',
metadata: 'MetadataDefinition',
music: 'MusicDefinition',
person: 'PersonDefinition',
phone_number: 'PhoneNumberDefinition',
science: 'ScienceDefinition',
system: 'SystemDefinition',
vehicle: 'VehicleDefinition',
word: 'WordDefinition',
};

const prettierTsOptions: Options = { ...options, parser: 'typescript' };
Expand Down Expand Up @@ -281,7 +281,7 @@ for (const locale of locales) {
let localeTitle = 'No title found';
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const metadata: MetadataDefinitions = require(pathMetadata).default;
const metadata: MetadataDefinition = require(pathMetadata).default;
const { title } = metadata;
if (!title) {
throw new Error(`No title property found on ${JSON.stringify(metadata)}`);
Expand All @@ -290,7 +290,7 @@ for (const locale of locales) {
localeTitle = title;
} catch (e) {
console.error(
`Failed to load ${pathMetadata}. Please make sure the file exists and exports MetadataDefinitions.`
`Failed to load ${pathMetadata}. Please make sure the file exists and exports a MetadataDefinition.`
);
console.error(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/airline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Airline, Airplane, Airport } from '../modules/airline';
import type { LocaleEntry } from './definitions';

export type AirlineDefinitions = LocaleEntry<{
export type AirlineDefinition = LocaleEntry<{
/**
* Some airline information
*/
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/animal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to animals.
*/
export type AnimalDefinitions = LocaleEntry<{
export type AnimalDefinition = LocaleEntry<{
bear: string[];
bird: string[];
cat: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to colors.
*/
export type ColorDefinitions = LocaleEntry<{
export type ColorDefinition = LocaleEntry<{
/**
* Human readable color names.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/commerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to commerce.
*/
export type CommerceDefinitions = LocaleEntry<{
export type CommerceDefinition = LocaleEntry<{
/**
* Department names inside a shop.
*/
Expand All @@ -12,7 +12,7 @@ export type CommerceDefinitions = LocaleEntry<{
/**
* Product name generation definitions.
*/
product_name: CommerceProductNameDefinitions;
product_name: CommerceProductNameDefinition;

/**
* Descriptions for products.
Expand All @@ -23,7 +23,7 @@ export type CommerceDefinitions = LocaleEntry<{
/**
* The possible definitions related to product name generation.
*/
export interface CommerceProductNameDefinitions {
export interface CommerceProductNameDefinition {
/**
* Adjectives describing a product (e.g. tasty).
*/
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to companies.
*/
export type CompanyDefinitions = LocaleEntry<{
export type CompanyDefinition = LocaleEntry<{
/**
* Business/products related adjectives that can be used to demonstrate data being viewed by a manager.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to databases.
*/
export type DatabaseDefinitions = LocaleEntry<{
export type DatabaseDefinition = LocaleEntry<{
/**
* Database engines.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to dates.
*/
export type DateDefinitions = LocaleEntry<{
export type DateDefinition = LocaleEntry<{
/**
* The translations for months (January - December).
*/
Expand Down
84 changes: 41 additions & 43 deletions src/definitions/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { AirlineDefinitions } from './airline';
import type { AnimalDefinitions } from './animal';
import type { ColorDefinitions } from './color';
import type { CommerceDefinitions } from './commerce';
import type { CompanyDefinitions } from './company';
import type { DatabaseDefinitions } from './database';
import type { DateDefinitions } from './date';
import type { FinanceDefinitions } from './finance';
import type { HackerDefinitions } from './hacker';
import type { InternetDefinitions } from './internet';
import type { LocationDefinitions } from './location';
import type { LoremDefinitions } from './lorem';
import type { MetadataDefinitions } from './metadata';
import type { MusicDefinitions } from './music';
import type { PersonDefinitions } from './person';
import type { PhoneNumberDefinitions } from './phone_number';
import type { ScienceDefinitions } from './science';
import type { SystemDefinitions } from './system';
import type { VehicleDefinitions } from './vehicle';
import type { WordDefinitions } from './word';
import type { AirlineDefinition } from './airline';
import type { AnimalDefinition } from './animal';
import type { ColorDefinition } from './color';
import type { CommerceDefinition } from './commerce';
import type { CompanyDefinition } from './company';
import type { DatabaseDefinition } from './database';
import type { DateDefinition } from './date';
import type { FinanceDefinition } from './finance';
import type { HackerDefinition } from './hacker';
import type { InternetDefinition } from './internet';
import type { LocationDefinition } from './location';
import type { LoremDefinition } from './lorem';
import type { MetadataDefinition } from './metadata';
import type { MusicDefinition } from './music';
import type { PersonDefinition } from './person';
import type { PhoneNumberDefinition } from './phone_number';
import type { ScienceDefinition } from './science';
import type { SystemDefinition } from './system';
import type { VehicleDefinition } from './vehicle';
import type { WordDefinition } from './word';

/**
* Wrapper type for all definition categories that will make all properties optional and allow extra properties.
Expand All @@ -28,28 +28,26 @@ export type LocaleEntry<T extends Record<string, unknown>> = {

/**
* The definitions as used by the translations/locales.
* This is basically the same as Definitions with the exception,
* that most properties are optional and extra properties are allowed.
*/
export type LocaleDefinition = {
metadata?: MetadataDefinitions;
airline?: AirlineDefinitions;
animal?: AnimalDefinitions;
color?: ColorDefinitions;
commerce?: CommerceDefinitions;
company?: CompanyDefinitions;
database?: DatabaseDefinitions;
date?: DateDefinitions;
finance?: FinanceDefinitions;
hacker?: HackerDefinitions;
internet?: InternetDefinitions;
location?: LocationDefinitions;
lorem?: LoremDefinitions;
music?: MusicDefinitions;
person?: PersonDefinitions;
phone_number?: PhoneNumberDefinitions;
science?: ScienceDefinitions;
system?: SystemDefinitions;
vehicle?: VehicleDefinitions;
word?: WordDefinitions;
} & Record<string, Record<string, unknown> | undefined>;
metadata?: MetadataDefinition;
airline?: AirlineDefinition;
animal?: AnimalDefinition;
color?: ColorDefinition;
commerce?: CommerceDefinition;
company?: CompanyDefinition;
database?: DatabaseDefinition;
date?: DateDefinition;
finance?: FinanceDefinition;
hacker?: HackerDefinition;
internet?: InternetDefinition;
location?: LocationDefinition;
lorem?: LoremDefinition;
music?: MusicDefinition;
person?: PersonDefinition;
phone_number?: PhoneNumberDefinition;
science?: ScienceDefinition;
system?: SystemDefinition;
vehicle?: VehicleDefinition;
word?: WordDefinition;
} & Record<string, Record<string, unknown>>;
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/definitions/finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to finance.
*/
export type FinanceDefinitions = LocaleEntry<{
export type FinanceDefinition = LocaleEntry<{
/**
* The types of accounts/purposes of an account (e.g. `Savings` account).
*/
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/hacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to computers.
*/
export type HackerDefinitions = LocaleEntry<{
export type HackerDefinition = LocaleEntry<{
/**
* Generic computer related abbreviations (e.g. `RAM`, `EXE`).
*/
Expand Down
45 changes: 21 additions & 24 deletions src/definitions/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
export type { AirlineDefinitions } from './airline';
export type { AnimalDefinitions } from './animal';
export type { ColorDefinitions } from './color';
export type { AirlineDefinition } from './airline';
export type { AnimalDefinition } from './animal';
export type { ColorDefinition } from './color';
export type {
CommerceDefinitions,
CommerceProductNameDefinitions,
CommerceDefinition,
CommerceProductNameDefinition,
} from './commerce';
export type { CompanyDefinitions } from './company';
export type { DatabaseDefinitions } from './database';
export type { DateDefinitions, DateEntryDefinition } from './date';
export type { CompanyDefinition } from './company';
export type { DatabaseDefinition } from './database';
export type { DateDefinition, DateEntryDefinition } from './date';
export type { LocaleDefinition, LocaleEntry } from './definitions';
export type { FinanceDefinitions } from './finance';
export type { HackerDefinitions } from './hacker';
export type { InternetDefinitions } from './internet';
export type { LocationDefinitions } from './location';
export type { LoremDefinitions } from './lorem';
export type { MetadataDefinitions } from './metadata';
export type { MusicDefinitions } from './music';
export type { PersonDefinitions, PersonTitleDefinitions } from './person';
export type { PhoneNumberDefinitions } from './phone_number';
export type { ScienceDefinitions } from './science';
export type {
SystemDefinitions,
SystemMimeTypeEntryDefinitions,
} from './system';
export type { VehicleDefinitions } from './vehicle';
export type { WordDefinitions } from './word';
export type { FinanceDefinition } from './finance';
export type { HackerDefinition } from './hacker';
export type { InternetDefinition } from './internet';
export type { LocationDefinition } from './location';
export type { LoremDefinition } from './lorem';
export type { MetadataDefinition } from './metadata';
export type { MusicDefinition } from './music';
export type { PersonDefinition, PersonTitleDefinition } from './person';
export type { PhoneNumberDefinition } from './phone_number';
export type { ScienceDefinition } from './science';
export type { SystemDefinition, SystemMimeTypeEntryDefinition } from './system';
export type { VehicleDefinition } from './vehicle';
export type { WordDefinition } from './word';
2 changes: 1 addition & 1 deletion src/definitions/internet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to internet stuff.
*/
export type InternetDefinitions = LocaleEntry<{
export type InternetDefinition = LocaleEntry<{
/**
* Common top level and similar domains (e.g `de`, `co.uk`).
*/
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to addresses and locations.
*/
export type LocationDefinitions = LocaleEntry<{
export type LocationDefinition = LocaleEntry<{
/**
* Postcodes patterns by state
*/
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/lorem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to lorem texts.
*/
export type LoremDefinitions = LocaleEntry<{
export type LoremDefinition = LocaleEntry<{
/**
* Lorem words used to generate dummy texts.
*/
Expand Down
10 changes: 5 additions & 5 deletions src/definitions/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* Metadata for pre-built locales.
*/
export type PreBuiltMetadataDefinitions = {
export type PreBuiltMetadataDefinition = {
/**
* The English name of the language (and the specific country, if defined).
*/
Expand Down Expand Up @@ -43,8 +43,8 @@ export type PreBuiltMetadataDefinitions = {
/**
* Metadata for pre-built locales for a specific country.
*/
export type PreBuiltMetadataDefinitionsForCountry =
PreBuiltMetadataDefinitions & {
export type PreBuiltMetadataDefinitionForCountry =
PreBuiltMetadataDefinition & {
/**
* The ISO 3166-1 alpha-2 code of the country.
*
Expand All @@ -56,5 +56,5 @@ export type PreBuiltMetadataDefinitionsForCountry =
/**
* Metadata for the current locale.
*/
export type MetadataDefinitions =
LocaleEntry<PreBuiltMetadataDefinitionsForCountry>;
export type MetadataDefinition =
LocaleEntry<PreBuiltMetadataDefinitionForCountry>;
2 changes: 1 addition & 1 deletion src/definitions/music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { LocaleEntry } from './definitions';
/**
* The possible definitions related to music.
*/
export type MusicDefinitions = LocaleEntry<{
export type MusicDefinition = LocaleEntry<{
/**
* The names of some music genres.
*/
Expand Down
Loading