Languages
Solid Memo speaks English (en), Swedish (sv), Korean (ko),
German (de), Spanish (es) and French (fr). Every text the app
shows comes from a message file. Text that comes with the data — deck
titles and descriptions, card text — is shown in the language the user
says it's in
(Text in the user's languages).
Which language
pickLocale (locale.ts) decides, in
order:
- the language the user chose with the language list (a globe and
the language's name in itself) atop every screen, or under Language
in the study preferences. The device store keeps it on
this device
(deviceChoices.ts,
key
solid-memo:language), not in the pod, which the sign-in screens come before; - else the first of the browser's preferred languages
(
navigator.languages) the app speaks —sv-SEcounts assv; - else English.
AppShell, Solid Memo's and the Studio's shell, sets
<html lang> to it. Deck and card text is shown in the same language,
else the browser's, else English, else the first language it has
(shown in langText.ts). Text in
another language than the page's is marked with its own lang
(readerLang, ReaderText); untagged text and text in no language
(zxx) get none.
A deck may have its own card language, chosen by the learner and kept
on the deck in the pod (sm:deckCardLanguage,
data-model.md). Its card text (fronts,
backs, notes, labels, picture descriptions and wrong options) ranks
that language first:
shown(text, [deckLang, locale, ...navigator.languages]). On a
course's own screens (a course is a deck), it covers all the course's
text: the course's and each chapter's title and description, and each
step's theory, its chunks counted in the language shown. Elsewhere only
card text follows it; a deck's keywords, the app's own text and
<html lang> never do. Course text in another language is marked with
its own lang, as card text is.
A screen of one deck's cards sits under a CardLanguage with the
deck's language: study, the Browser, a card's page, and every screen
of a deck in the Studio. A cram of the leeches takes the language of the
deck of the card up. The components that show card text (CardFace,
DataText, DataLine, CardText) take their reader from
useCardText. A screen naming cards of several decks, such as the leeches
or the Studio's command palette, takes each deck's reader from
cardReader(deck.cardLanguage)
(cardLanguage.tsx).
A course's page, chapter and final review sit under a CourseLanguage,
a CardLanguage for its questions' cards too. The components that show
a course's own text (CourseText, DataProse, useProseChunks) take
their reader from useCourseText. On those routes the trail's course
and chapter, and so the page's title, are named in it. Elsewhere, as in
the Studio's trial of a course and the courses above the deck list and
their statistics, readerText shows card and course text as any text.
The learner chooses it on the deck's Preferences page
(DeckCardLanguageForm, #/deck-preferences): first "The app's
language", the default, which clears the choice, then the languages the
deck's cards state on their fronts and backs (preferableCardLanguages:
no untagged text, no zxx). It lists at most LANGUAGE_CHOICE_LIMIT
(100) of them, the most used. A choice the cards no longer state stays
listed, to be cleared.
For a course's deck (Deck.course, or a release that's a course for an
older copy) the picker is "Course language", with words of its own. It
lists every language the course states (preferableCourseLanguages):
its deck's cards, and its release's cards, title, description, chapter
titles and descriptions and step theory (the deck starts with no cards
and gains one only as its question is first answered).
The outline is read as the courses above the deck list read it
(queries.courseStrip); until then the list holds only the default and
the choice. The course's page links to its preferences
(CourseLinks.preferencesHref; the Studio's trial gives none). Its
screens read the choice from the deck list, which saving refreshes.
A deck's keywords, several per language, are shown only in the chosen
language. keywordsIn (keywords.ts)
shows those under a tag with its primary subtag (sv, sv-se, sv-fi
for Swedish) and those in no stated language (untagged and zxx), each
once. There's no fallback: without those, none show.
Library decks carry their title, description and keywords in every
language the app speaks, so every reader sees keywords on them.
npm run library:check holds each deck's newest version to it: a
language added to LOCALES fails every deck until a new version adds it
(deck-library.md).
The library's search covers titles, descriptions and keywords in every
language.
Text in the user's languages
Text the user writes — a deck's name, description and keywords, a card's sides, notes, labels and picture descriptions — is saved language-tagged, one value per language (keywords: a comma-separated list per language). Its language is the one the user states (deck format 6, card format 7: shapes.md), never the page's: an English speaker on a Swedish page types English.
- Every field has a language picker (
LangTextFieldwithLanguagePickerin packages/ui/src/ui): a button that says the language ("Language: Swedish", or "not stated") and opens in place onto radios. They offer the text's own language, what the deck uses, the languages chosen recently on this device, the page's language, English, Swedish, the browser's languages, "No language (codes, numbers, symbols)" (zxx) and any other by its code. What the deck uses is at mostLANGUAGE_CHOICE_LIMIT(100) of the languages of its name, description and keywords, by tag (textLanguages), after the text's own language.canonicalTag(languageTag.ts) checks a code. The button sits in its text's box, at the text's end (under a textarea, in a bar of its own), and shows the name alone ("Swedish", or "Language?" while none is chosen); a screen reader reads its full name. A translation is a row with its own picker. Changing the language keeps the text. The translations are drawn only while their section is open, and at mostLANGUAGE_CHOICE_LIMITof a text's, since a text read from a pod or a release may be in any number of languages. A note says how many more there are, and saving keeps them as they are; a text with that many gets no new one. A translation still to get its language is always drawn, so the user can give it one. The limit is the one the language pickers use, set in cardQuery.ts. - Nothing is chosen from the page. A language is preselected only
from evidence, first the text's own tag. On a card, the next is the
language the last card added in the same form had (sticky), else the
one the deck's cards use most for that part (
usualTag, throughdeckLanguagesin deckLanguages.ts). A note, label, picture description or deck name then falls back to the one chosen last on this device, kept in the browser, not the pod (remembered.ts, keyssolid-memo:recentLanguages.deckandsolid-memo:recentLanguages.own). Choosing a language for an empty field fills the untouched empty fields of the same kind in the form. - Text the user writes or changes always has its language. Saving
text without one is refused (
textNeedsLanguage), focusing that field's picker. The app never writes untagged text anew, nor copies text under English on its own. - Tags are stored in lower case (
pt-br), as the pod reads them. A tag is looked up as an own key, never throughObject.prototype. A tag with a subtag over 8 characters (constructor) isn't written: the pod's Turtle parser refuses it, so an imported deck file leaves such text out (data model).Intl.DisplayNamesnames them (languageLabel: "Swedish — svenska (sv)"); a tag Intl can't name is shown as itself. - Text over several lines keeps its breaks. A card's text saved
with a line break (a line feed or a carriage return), in any language,
is edited in a textarea, and stays one in that editor once a save
drops the breaks (focus stays put). Editing never drops a break, in
labels and picture descriptions too. A card in Markdown has its sides
and notes in textareas whatever they hold
(markdown.md), and a deck's
description is always one. In a textarea Enter starts a new line and
Ctrl+Enter or ⌘+Enter submits the form, as the textarea states
(
aria-keyshortcuts). - An input method's keys are its own. While one composes text
(Korean, Japanese or Chinese, for example), the Enter or Escape that
commits or cancels it does nothing in the app (
composing: the event'sisComposing, or keyCode 229, all Safari gives once the composition has ended). That holds for every Enter or Escape handled while a field may have the focus: Ctrl+Enter in a textarea, Enter and Escape in a language picker, Escape in a name edited in place and on an enlarged picture. A form's own submit on Enter is left to the browser, which commits the syllable first. - Text written right to left keeps its own direction. Arabic,
Persian, Urdu, Hebrew and the like run right to left wherever the
page marks the text with its language (
lang="ar", asreaderLangand the editor's fields do). The style sheet's:lang()rule sets that direction, isolated from the text around it, not adiron each element; a block starts at the right (text-align: start). Such text set into a sentence as plain text (a card's name in "Remove the card "{card}"?", a title, a picture's description) is isolated between U+2068 and U+2069 (isolated), keeping the sentence's punctuation in place. No language the app speaks is written right to left yet, so nothing mirrors.
Older data may not say its language (card sides before card format 5,
keywords before deck format 6); the app doesn't guess it.
Untagged keywords are kept, or removed, as they are; a keyword added or
changed needs its language. While any is left, the deck's page says so
(DeckLanguagesNotice), linking to the Languages section of its
preferences (DeckLanguagesSection), where untagged fronts or backs
get one language at once (stateCardLanguages). The
Browser marks the cards with a side in no stated language and can list
only those (languages=unstated in its URL). Text still as its library
release has it is left alone, for a later release to update.
The same words under several languages are text in each, accepted as they are: "Stockholm"@en with "Stockholm"@sv, like "1969"@sv with "1969"@it. That includes the identical English copies the app wrote while the formats required English, which it can't tell from a real translation and neither flags nor offers for removal. In the editor each language is an entry, edited, retagged or removed like any other translation.
The deck's page weighs its text on its own (deckLanguageIssues over
deckLanguages, pure domain functions) from the cards it has read and
the deck's library release (UseCases.deckRelease), not a use case of
its own, which would read the cards again. When the release can't be read, the
library's text can't be told from the user's. If the deck's text holds
none to settle even counting the library's, nothing is said; otherwise
the notice says the check couldn't be made, not counts, and still links
to the Languages section, which shows why.
Formatted text
In Markdown (markdown.md) each language's value is its
own Markdown document under its own tag, and every rule above holds of
it: shownTag,
textNeedsLanguage, one text per language, a distractor in the back's
languages. A code block inside @en text keeps @en, and a code-only
back may be zxx. The card editor hints under each language's text;
its preview shows the main one, the one being written.
The app's own words about Markdown are messages:
cardContentFields.markdown* and .preview* the editor's, and
markdownHelp.* its cheat sheet's (the syntax is code, the same in
every language). markdownProblem.* has one for each problem
markdownProblems names, and markdown.* the names of a code block, a
table region and a link's host.
Messages
packages/ui/src/i18n/en.json and the
other languages' files beside it (sv.json, ko.json, de.json,
es.json, fr.json) hold one namespace per component (deckList,
instancePicker, …) and a few shared ones (common, language,
footer). studio holds what the page says of the
Studio before its code is here: its name, tagline, the
links to it and back, and that it's opening; its screens have their own
files (The Studio's messages). Components read
them through useI18n() (i18n.tsx):
const { t, tx, readerText, formatDate, directionLabel } = useI18n();
t("deckList.heading"); // "Decks"
t("common.cardCount", { count: 3 }); // "3 cards" — a plural message
tx("app.loggedInAs", { name: <ExternalLink … /> }); // markup inside a sentence
- A message's
{name}placeholders are filled from the values given; a number is written as the language writes one ("1,000", "1 000"); a value that must keep its digits (a year) is given as text. - A plural message gives a form for each plural category of its
language, picked by
countthroughIntl.PluralRules. English, Swedish and German have{ "one": …, "other": … }; Spanish and French{ "one": …, "many": …, "other": … }(many for a million and more: "1 000 000 de cartes"); Korean only{ "other": … }. The rules are the Unicode CLDR plural rules (by language) in the browser's CLDR version (policy.md). A message without a count takes other. - A sentence with a link stays one message (
tx), the link where the language's word order puts it. - Keys are string literals, typed from
en.json: a misspelled key fails the type check.
A release's highlights for users are messages under
whatsNew.highlight, one per id
(releasing.md).
Tests in i18n.test.tsx hold
every other message file to exactly the keys and placeholders of
en.json, and every key the source asks for to one en.json has.
Components outside a provider speak English: component tests query
English text without setup.
Loading a language
The page fetches only its own language's messages. en.json
is imported statically: the fallback, the crash screen's language when
nothing else has loaded, and the source of MessageKey. Every other
language's file is fetched with import() (UI_CATALOGS in
i18n.tsx), a chunk of its own, which build.test.ts checks
(testing.md).
- Before the first render,
main.tsxwaits for the page language's messages (loadLocale); English waits for nothing. If the fetch fails, the page starts in English. t()stays synchronous. Choosing a language (chooseLocale) fetches its messages, then switches; until then the screen keeps its language, but the language controls already show the one chosen (choice). If they can't be fetched, the language list says so (language.unavailable), and the language and the controls are unchanged. Of two quick choices, the later wins, whichever's messages arrive first.- A language whose messages aren't fetched speaks English with its own dates and numbers.
- The tests fetch every language before they run (packages/ui/src/test/setup.ts). A user journey fetches them as the built app does: from the browser's language, the language list and Preferences, and one that can't be fetched (testing.md).
The Studio's messages
The Studio's screens say the rest of studio.*, from a file per
language in apps/studio/src/i18n/, which
come with the Studio's chunk: a learner who never opens the Studio
downloads none (studio.md).
STUDIO_CATALOGSin catalogs.ts holds English statically and fetches each other language withimport(). Once the Studio's code is fetched, the page adds them to its own (addCatalogs) in each language it has fetchedui's in, then shows the Studio; choosing a language afterward fetches both. A message is looked for inui's first, so the Studio's share no key withui's.- The same file adds the Studio's English to
EnglishCatalogs, the interfaceMessageKeyis made from: wherever the Studio's code is, its keys are typed and a misspelled one fails the type check;uialone doesn't know them. - Tests in catalogs.test.ts
hold the Studio's files to its English, as
ui's are (test/catalogs.ts), and every key the Studio's source asks for to one of the two English files. The Studio's tests add its messages before they run (apps/studio/src/test/setup.ts).
Translations
English is the source; Swedish is the maintainer's own. Korean, German, Spanish and French were translated with AI: one model drafted each, following a glossary per language (register, typography, the words for deck, card, review…), then an independent check translated each message back into English and fixed what drifted. No native speaker has reviewed them yet; corrections from one are welcome. German says du, Spanish tú (neutral, international), French vous, Korean the polite 해요 style.
The About page, a static page for
search engines and people deciding whether to use Solid Memo, is
outside the app and its catalogs, in English only for now. Pages per
language, linked to each other with hreflang, can come later.
These docs, which the site serves at /docs/ too
(deployment.md), change with
the code and are in English only, as their pages say (lang="en"). The
app's footer links to them with hreflang="en", and its label says "in
English" in every other language (footer.docs), as the footer's link
to the About page, /about/, does (footer.about).
Adding a language
- Add its code to
LOCALESinpackages/core/domain/src/locale.ts, and to the languages the page names in its JSON-LD:inLanguageand the store listing'slanguagein apps/web/index.html, and the listbuild.test.tsexpects ("the page's structured data"). - Add
packages/ui/src/i18n/<code>.jsonwith every key ofen.json, and register it inUI_CATALOGSini18n.tsxas animport()(Loading a language). Add it to the chunks the build test expects (build.test.ts, "the messages"). Do the same for the Studio:apps/studio/src/i18n/<code>.json, with every key of the Studio'sen.json, inSTUDIO_CATALOGSincatalogs.ts. - Name it in itself in
LANGUAGE_NAMESinLanguageSelector.tsx. - Give each plural message exactly the forms its plural rules name
(
new Intl.PluralRules("<code>").resolvedOptions().pluralCategories): only other in Korean, Japanese and Chinese; one, many and other in Spanish and French; one, few, many and other in Polish and Ukrainian. - Register both files in the journeys' harness:
LocaleandCATALOGSin e2e/journeys/harness/strings.ts, and the language's name inswitchLanguagein e2e/journeys/pages/Chrome.ts. - Extend the tests naming every language:
locale.test.ts,i18n.test.tsx(its catalogs, a plural, a date, a language's name), the Studio'scatalogs.test.ts,LanguageSelector.test.tsx,PreferencesScreen.test.tsx. - Name and define every topic in it in
ns/vocab/topics.ttl (vocab.md):
the scheme's
dcterms:titleandskos:definition, and each concept'sskos:prefLabelandskos:definition, withowl:versionInfobumped and askos:changeNotesaying so. Then runnpm run format:turtle,npm run generateandnpm run crosscheck, and update the tests that compare topic labels (concepts.test.ts,library.test.ts). - If its script needs its own fonts, line breaking or heading
treatment, add
:lang(<code>)rules topackages/ui/src/style.css, with tests instyle.test.ts, as Korean has (theme.md). The Studio's headings are in the body's type and weight whatever the language (apps/studio/src/ui/studio.css); check them there too. - A language written right to left, as the app's own, needs the page
mirrored (
dir="rtl"on<html>) and every layout rule that names a side made logical; the style sheet already sets its text's direction.
The shapes' sh:messages stay in English and Swedish; a new language
needs none. Its readers see a shape's own message in English, marked
so, and the validator's messages in their language
(shapes.md).