Skip to content

Translate · Modules

6 modules · 31 exports · 0 repositories · 2 e2e tests · 3 routes

Who imports who · hover a node
Depends onTranslate modulesUsed byTranslationCatalog.serverTranslationDrafts5 expo…TranslationEntries.serverTranslationSyntax5 expo…TranslationUnits11 expo…TranslationUsage.serverLoaders4 filesRoutes1 fileComponents4 filesScripts2 filesOther1 file

TranslationCatalog

serverapp/features/translate/core/TranslationCatalog.server.ts

No overview comment at the top of the file.

Imports
TranslationUnits
Used by
4 loaders

Functions & values

function

units

:33

Translatable units of the language, derived from the deployed English translations

export function units(
	language: TranslatableLanguage,
): TranslationUnits.TranslationUnit[]
function

english

:49

The deployed English translations without the namespaces generated from game data, most visible namespaces first

export function english(): TranslationUnits.Translations
function

translations

:67

The deployed translations of the language, without the namespaces generated from game data. A regional variant includes what it inherits from its parent language.

export function translations(
	language: TranslatableLanguage,
): TranslationUnits.Translations
function

inherited

:88

What the language inherits from its parent language, empty if it's not a regional variant

export function inherited(
	language: TranslatableLanguage,
): TranslationUnits.Translations
function

progressByLanguage

:96

Translation progress of every translatable language

export function progressByLanguage()

TranslationDrafts

app/features/translate/core/TranslationDrafts.ts

No overview comment at the top of the file.

Imports
TranslationSyntaxTranslationUnits
Used by
1 route3 components

Types

type

Catalog

:5

What drafts are checked against: the English translations and the language's current ones

export type Catalog = {
	language: string;
	english: TranslationUnits.Translations;
	/** Includes what a regional variant inherits from its parent language */
	translations: TranslationUnits.Translations;
	/** What a regional variant inherits from its parent language, left out of its files */
	inherited: TranslationUnits.Translations;
};

Functions & values

function

sort

:29

Splits the drafts into the ones still worth merging and obsolete ones: drafts of keys that no longer exist, translated from English text that has changed since, equal to the current translation or with broken syntax.

  • @example

    TranslationDrafts.sort({ catalog, drafts: { common: { save: { value: "Speichern", source: "Save" } } } }); // { pending: { common: { save: "Speichern" } }, obsolete: [] }

export function sort({
	catalog,
	drafts,
}: {
	catalog: Catalog;
	drafts: TranslationUnits.TranslationDrafts;
})
Unit tests (2)
function

mergedFiles

:60

Full translation jsons of the namespaces the pending drafts touch, the drafts written over the current translations in English key order, as pnpm run i18n:sync writes them. A regional variant's files leave out what equals its parent language's translation.

export function mergedFiles({
	catalog,
	pending,
}: {
	catalog: Catalog;
	pending: TranslationUnits.Translations;
}): TranslationUnits.Translations
Unit tests (3)
function

fromFiles

:96

Drafts from uploaded translation jsons (namespace -> parsed file): the values that differ from the current ones and keep the English syntax

export function fromFiles({
	catalog,
	files,
}: {
	catalog: Catalog;
	files: Record<string, Record<string, unknown>>;
}): TranslationUnits.TranslationDrafts
Unit tests (1)
function

units

:123

The catalog's translatable units, see {@link TranslationUnits.fromEnglish}

export function units(catalog: Catalog): TranslationUnits.TranslationUnit[]

TranslationEntries

serverapp/features/translate/core/TranslationEntries.server.ts

No overview comment at the top of the file.

Imports
TranslationUnitsTranslationUsage.server
Used by
2 loaders1 component

Types

type

TranslationEntry

no JSDoc:6
export type TranslationEntry = ReturnType<typeof toEntry>;

Functions & values

function

toEntry

:9

The unit with its current translations and where it's used, as shown on the /translate page

export function toEntry(
	unit: TranslationUnits.TranslationUnit,
	translations: TranslationUnits.Translations,
)
function

namespaceSummaries

:20

Translation progress per namespace

export function namespaceSummaries(
	units: TranslationUnits.TranslationUnit[],
	translations: TranslationUnits.Translations,
)

TranslationSyntax

app/features/translate/core/TranslationSyntax.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module1 component1 script

Types

type

SyntaxIssue

no JSDoc:11
export type SyntaxIssue =
	| { type: "EMPTY" }
	| { type: "MISSING_PLACEHOLDER"; placeholder: string }
	| { type: "UNKNOWN_PLACEHOLDER"; placeholder: string }
	| { type: "BROKEN_TAGS" }
	| { type: "TAG_MUST_BE_EMPTY"; placeholder: string };
type

TextSegment

no JSDoc:18
export type TextSegment = {
	text: string;
	isPlaceholder: boolean;
};
Only used inside the module

Functions & values

function

validate

:34

Validates that a translation keeps the special syntax of its English source: every {{variable}}, $t(nesting) and <tag> of the source and nothing else. Tags may wrap different words but must stay balanced, and a tag the source leaves empty (<0></0>) must stay empty. In plural forms {{count}} is optional since many languages spell out e.g. the singular form.

  • @example

    TranslationSyntax.validate({ source: "by {{author}}", translation: "von {{author}}" }); // [] TranslationSyntax.validate({ source: "by {{author}}", translation: "von" }); // [{ type: "MISSING_PLACEHOLDER", placeholder: "{{author}}" }]

export function validate({
	source,
	translation,
	isPlural = false,
}: {
	source: string;
	translation: string;
	isPlural?: boolean;
}): SyntaxIssue[]
Unit tests (5)
function

placeholders

:106

Placeholders of the text a translation has to keep, in order of first appearance. Paired tags are given as one placeholder with nothing between them (<1></1>) so it can be inserted as is.

  • @example

    TranslationSyntax.placeholders("See <1>FAQ</1> for {{what}}"); // ["<1></1>", "{{what}}"]

export function placeholders(source: string): string[]
Unit tests (1)
function

segments

:121

Splits the text into plain text and placeholder segments, for highlighting the parts a translator must keep as they are.

export function segments(text: string): TextSegment[]
Unit tests (1)

TranslationUnits

app/features/translate/core/TranslationUnits.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
2 loaders3 modules2 components1 script1 other

Types

type

Translations

no JSDoc:3
export type Translations = Record<string, Record<string, string>>;
type

TranslationDraft

no JSDoc:5
export type TranslationDraft = {
	value: string;
	/** The English text the draft was translated from */
	source: string;
};
type

TranslationDrafts

:12

Namespace -> key -> draft

export type TranslationDrafts = Record<
	string,
	Record<string, TranslationDraft>
>;
type

TranslationForm

no JSDoc:17
export type TranslationForm = {
	/** Key in the language's translation json */
	key: string;
	/** `null` if the unit is not pluralized */
	pluralCategory: Intl.LDMLPluralRule | null;
	/** The English text this form is translated from */
	source: string;
};
type

TranslationUnit

:27

One translatable string, which consists of several forms in the case of a pluralized string

export type TranslationUnit = {
	namespace: string;
	/** The key without its plural suffix */
	id: string;
	isPlural: boolean;
	forms: TranslationForm[];
};

Functions & values

function

fromEnglish

:44

Every translatable unit of the language derived from the English translations. A pluralized English string (x_one & x_other) is expanded into the plural categories of the language, using the bare key for languages with only one category (what pnpm run i18n:sync produces).

  • @example

    TranslationUnits.fromEnglish({ english: { user: { "sets_one": "{{count}} set", "sets_other": "{{count}} sets" } }, language: "pl" }); // [{ namespace: "user", id: "sets", isPlural: true, forms: [{ key: "sets_one", ... }, { key: "sets_few", ... }, ...] }]

export function fromEnglish({
	english,
	language,
	excludedNamespaces = [],
}: {
	english: Translations;
	language: string;
	excludedNamespaces?: readonly string[];
}): TranslationUnit[]
Unit tests (5)
function

filter

:103

Units in the namespace (null for all) whose key, English text or translation contains the search

export function filter({
	units,
	translations,
	namespace,
	search,
}: {
	units: TranslationUnit[];
	translations: Translations;
	namespace: string | null;
	search: string;
})
function

withTranslations

:131

The unit with the current translation of each of its forms, empty string when untranslated

export function withTranslations(
	unit: TranslationUnit,
	translations: Translations,
)
function

isTranslated

:145

Whether every form of the unit has a translation

export function isTranslated(
	unit: TranslationUnit,
	translations: Translations,
): boolean
function

progress

:155

Count of units and how many of them are fully translated

export function progress(
	units: TranslationUnit[],
	translations: Translations,
): { total: number; translated: number }
Unit tests (1)
function

isDraftPending

:169

Whether a draft written for the form is still worth merging: the English text it was translated from is unchanged and it differs from the current translation.

export function isDraftPending({
	form,
	draft,
	currentTranslation,
}: {
	form: TranslationForm;
	draft: TranslationDraft;
	currentTranslation: string | undefined;
}): boolean
Unit tests (1)

TranslationUsage

serverapp/features/translate/core/TranslationUsage.server.ts

No overview comment at the top of the file.

Imports
no other modules
Used by
1 module

Types

type

TranslationUsage

no JSDoc:14
export type TranslationUsage = {
	/** Used by a component rendered on every page e.g. the navigation */
	isSiteWide: boolean;
	/** Route paths e.g. `/u/:identifier/builds` */
	routes: string[];
	/** Source files relative to the repository root */
	files: string[];
};

Functions & values

function

forUnit

:26

Where in the codebase the translation unit is used, null if it could not be determined (e.g. dynamically built key)

export function forUnit({
	namespace,
	id,
}: {
	namespace: string;
	id: string;
}): TranslationUsage | null