Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions docs/LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The contents of the file should be as follows:
"joiningScript": boolean,
"orderedByFrequency": boolean,
"bcp47": string,
"fallbackFont":string,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "preferredFont" is a better name, since it's used at the top of the list

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is second in the list, so the first fallback font. Maybe we just name it font?!

"words": string[]
}
```
Expand All @@ -34,6 +35,7 @@ It is recommended that you familiarize yourselves with JSON before adding a lang
For `bcp47` put your languages [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag).
If the words you're adding are ordered by frequency (most common words at the top, least at the bottom) set the value of `orderedByFrequency` to `true`, otherwise `false`.
Finally, add your list of words to the `words` field.
If the language is not rendered correctly, you can provide a `fallbackFont`. The font needs to be one of monkeytypes fonts. Check the [fonts documentation](./FONTS.md).

Then, go to `packages/schemas/src/languages.ts` and add your new language name at the _end_ of the `LanguageSchema` enum. Make sure to end the line with a comma. Make sure to add all your language names if you have created multiple word lists of differing lengths in the same language.

Expand Down
18 changes: 13 additions & 5 deletions frontend/src/ts/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { qs, qsr } from "./utils/dom";
import { createEffect } from "solid-js";
import fileStorage from "./utils/file-storage";
import { convertRemToPixels } from "./utils/numbers";
import { getLanguage } from "./utils/json-data";

let isPreviewingFont = false;
export function previewFontFamily(font: FontName): void {
Expand Down Expand Up @@ -48,10 +49,17 @@ export async function applyFontFamily(): Promise<void> {
}`);
}

document.documentElement.style.setProperty(
"--font",
`"${font}", "Roboto Mono", "Vazirharf", monospace`,
);
const fallbackFont = (await getLanguage(Config.language))?.fallbackFont;

const fonts = [
font,
fallbackFont !== undefined ? `"${fallbackFont}"` : undefined,
'"Roboto Mono"',
'"Vazirharf"',
"monospace",
].filter((it) => it !== undefined);

document.documentElement.style.setProperty("--font", fonts.join(","));
}

export function clearFontPreview(): void {
Expand Down Expand Up @@ -135,7 +143,7 @@ createEffect(() => {
});

configEvent.subscribe(async ({ key }) => {
if (key === "fontFamily") {
if (key === "fontFamily" || key === "language") {
await applyFontFamily();
}
});
1 change: 1 addition & 0 deletions frontend/static/languages/lao.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"joiningScript": false,
"orderedByFrequency": false,
"bcp47": "lo",
"fallbackFont": "Noto_Sans_Lao",
"words": [
"ຂ້ອຍ",
"ເຈົ້າ",
Expand Down
2 changes: 1 addition & 1 deletion packages/schemas/src/fonts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from "zod";
import { customEnumErrorHandler } from "./util";

const KnownFontNameSchema = z.enum(
export const KnownFontNameSchema = z.enum(
[
"Roboto_Mono",
"Noto_Naskh_Arabic",
Expand Down
2 changes: 2 additions & 0 deletions packages/schemas/src/languages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from "zod";
import { KnownFontNameSchema } from "./fonts";
import { customEnumErrorHandler } from "./util";

export const LanguageSchema = z.enum(
Expand Down Expand Up @@ -469,6 +470,7 @@ export const LanguageObjectSchema = z
.array(z.tuple([z.string().min(1), z.string().min(1)]))
.optional(),
bcp47: z.string().optional(),
fallbackFont: KnownFontNameSchema.optional(),
originalPunctuation: z.boolean().optional(),
})
.strict();
Expand Down
Loading