docs(rewrite): Add @experimental to LocaleDescriptions symbol and family properties

@experimental: It's not that widely supported but it gets the point across effectively.
This commit is contained in:
tecc 2023-09-15 15:25:36 +02:00
parent 93f0d5065f
commit a9c63b6cbd
No known key found for this signature in database
GPG Key ID: 622EEC5BAE5EBD3A

View File

@ -20,9 +20,23 @@ export interface LocaleDescription {
name: string;
url: string;
published: boolean;
/**
* This locale's language family.
*
* @experimental
* This is currently not used for published versions.
*/
symbol: string;
// This could technically be an enum but for now it's just a string as there
// doesn't seem to be any apparent benefit to including locales
/**
* This locale's language family.
*
* @experimental
* This is currently not used for published versions.
*
* @privateRemarks
* This could technically be an enum but for now it's just a string as there
* doesn't seem to be any apparent benefit to including locales
*/
family: string;
}
@ -36,12 +50,12 @@ export async function loadLocaleDescriptions(): Promise<
if (loadedDescriptions == undefined) {
loadedDescriptions = (
await import(
"file://" +
path.resolve(getConfig().localeDataPath, "locales.js")
)
"file://" +
path.resolve(getConfig().localeDataPath, "locales.js")
)
).default;
indexedDescriptions = Object.fromEntries(
loadedDescriptions.map((v) => [v.code, v])
loadedDescriptions.map((v) => [v.code, v]),
);
activeLocaleDescriptions = undefined;
}
@ -109,11 +123,11 @@ export class Locale {
private async readFile(parts: Array<string>): Promise<string>;
private async readFile<T>(
parts: Array<string>,
parser: (value: string) => T
parser: (value: string) => T,
): Promise<T>;
private async readFile<T>(
pathParts: Array<string>,
parser?: (value: string) => T
parser?: (value: string) => T,
) {
// Some may complain about this
const filePath = this.path(pathParts);
@ -127,7 +141,7 @@ export class Locale {
}
} catch (e) {
const err = new Error(
`[${this.code}] Could not load file ${filePath}: ${e}`
`[${this.code}] Could not load file ${filePath}: ${e}`,
);
err.cause = e;
throw err;
@ -141,7 +155,7 @@ export class Locale {
return await import(`file://${filePath}`);
} catch (e) {
const err = new Error(
`[${this.code}] Could not import file ${filePath}: ${e}`
`[${this.code}] Could not import file ${filePath}: ${e}`,
);
err.cause = e;
throw err;
@ -168,7 +182,7 @@ export class Locale {
this._config = await this.readFile(["config.suml"], suml.parse);
this._translations = await this.readFile(
["translations.suml"],
suml.parse
suml.parse,
);
// NOTE(tecc): This currently doesn't work because the morphemes.js files (as well as many others) rely on ESM syntax.
// This is both inconsistent with the locales.js and expectedTranslations.js files,
@ -178,7 +192,7 @@ export class Locale {
this._pronounsByAlias = {};
const pronouns = await this.readFile(
["pronouns/pronouns.tsv"],
tsvParse
tsvParse,
);
for (const pronoun of pronouns) {
const partial: Partial<Pronoun> = { forms: {} };
@ -223,7 +237,7 @@ export class Locale {
}
const examples = await this.readFile(
["pronouns/examples.tsv"],
tsvParse
tsvParse,
);
this._examples = [];
for (const example of examples) {
@ -252,6 +266,7 @@ export class Locale {
public get pronouns() {
return Object.values(this._pronouns);
}
public pronoun(key: string): Pronoun | null {
const index = this._pronounsByAlias[key];
if (index == null) {
@ -259,13 +274,15 @@ export class Locale {
}
return this._pronouns[index];
}
public get examples() {
return this._examples;
}
}
export function examplesFor(
pronoun: Pronoun,
examples: Array<PronounExample>
examples: Array<PronounExample>,
): Array<string> {
const finished = [];
@ -303,7 +320,7 @@ export function getLocale(localeCode: string): Locale | null {
if (locale == null) {
locale = new Locale(
localeCode,
path.resolve(getConfig().localeDataPath, localeCode)
path.resolve(getConfig().localeDataPath, localeCode),
);
loadedLocales[localeCode] = locale;
}
@ -320,8 +337,8 @@ export async function loadAllLocales() {
locale
.load()
.then(() =>
log.debug(`Successfully loaded locale ${locale.code}`)
)
log.debug(`Successfully loaded locale ${locale.code}`),
),
);
}
}