diff --git a/src/basis/Basis.test.ts b/src/basis/Basis.test.ts index 49e5e23a4..a77c59a30 100644 --- a/src/basis/Basis.test.ts +++ b/src/basis/Basis.test.ts @@ -8,9 +8,9 @@ import UnparsableExpression from '@nodes/UnparsableExpression'; import Project from '../models/Project'; import Example from '../nodes/Example'; import { Basis } from './Basis'; -import DefaultLocale from '../locale/DefaultLocale'; +import DefaultLocale, { DefaultLocales } from '../locale/DefaultLocale'; -const basis = Basis.getLocalizedBasis(DefaultLocale); +const basis = Basis.getLocalizedBasis(DefaultLocales); const source = new Source('basis', ''); const project = Project.make(null, 'test', source, [], DefaultLocale); @@ -66,7 +66,7 @@ function checkBasisNodes(nodes: Node[]) { )}\nPrimary node: ${conflictingNodes.primary.node.toWordplay()}\n\t${ conflict.constructor.name }\n${conflictingNodes.primary.explanation( - basis.locales[0], + basis.locales, context )}` ); diff --git a/src/basis/Basis.ts b/src/basis/Basis.ts index 8643023fd..b49712ee8 100644 --- a/src/basis/Basis.ts +++ b/src/basis/Basis.ts @@ -33,9 +33,10 @@ import { getNameLocales } from '../locale/getNameLocales'; import bootstrapStructure from './StructureBasis'; import { toTokens } from '../parser/toTokens'; import parseType from '../parser/paresType'; +import type Locales from '../locale/Locales'; export class Basis { - readonly locales: Locale[]; + readonly locales: Locales; readonly languages: LanguageCode[]; readonly shares: ReturnType; @@ -45,9 +46,9 @@ export class Basis { */ static readonly Bases: Map = new Map(); - constructor(locales: Locale[]) { + constructor(locales: Locales) { this.locales = locales; - this.languages = locales.map((locale) => locale.language); + this.languages = locales.getLanguages(); this.addStructure('none', bootstrapNone(locales)); this.addStructure('boolean', bootstrapBool(locales)); @@ -62,9 +63,8 @@ export class Basis { this.shares = createDefaultShares(locales); } - static getLocalizedBasis(locales: Locale | Locale[]) { - locales = Array.isArray(locales) ? locales : [locales]; - const languages = locales.map((locale) => locale.language); + static getLocalizedBasis(locales: Locales) { + const languages = locales.getLanguages(); const key = languages.join(','); const basis = Basis.Bases.get(key) ?? new Basis(locales); Basis.Bases.set(key, basis); @@ -160,7 +160,7 @@ export class Basis { } export function createBasisFunction( - locales: Locale[], + locales: Locales, text: (locale: Locale) => FunctionText, typeVars: TypeVariables | undefined, types: (Type | [Type, Expression])[], diff --git a/src/basis/BoolBasis.ts b/src/basis/BoolBasis.ts index 81d96baf7..b37f9caf6 100644 --- a/src/basis/BoolBasis.ts +++ b/src/basis/BoolBasis.ts @@ -13,8 +13,9 @@ import type Locale from '../locale/Locale'; import type { FunctionText, NameAndDoc } from '../locale/Locale'; import type Type from '../nodes/Type'; import AnyType from '../nodes/AnyType'; +import type Locales from '../locale/Locales'; -export default function bootstrapBool(locales: Locale[]) { +export default function bootstrapBool(locales: Locales) { function createBooleanFunction( text: (locale: Locale) => FunctionText, inputs: Type[], diff --git a/src/basis/InternalExpression.ts b/src/basis/InternalExpression.ts index 7388aeb89..4606a0d09 100644 --- a/src/basis/InternalExpression.ts +++ b/src/basis/InternalExpression.ts @@ -9,7 +9,6 @@ import type Context from '@nodes/Context'; import type TypeSet from '@nodes/TypeSet'; import StartFinish from '@runtime/StartFinish'; import SimpleExpression from '@nodes/SimpleExpression'; -import type Locale from '@locale/Locale'; import InternalException from '@values/InternalException'; import Glyphs from '../lore/Glyphs'; import concretize from '../locale/concretize'; @@ -18,6 +17,7 @@ import Start from '@runtime/Start'; import Finish from '@runtime/Finish'; import { toTokens } from '../parser/toTokens'; import parseType from '../parser/paresType'; +import type Locales from '../locale/Locales'; export default class InternalExpression extends SimpleExpression { readonly type: Type; @@ -106,12 +106,15 @@ export default class InternalExpression extends SimpleExpression { return this; } - getNodeLocale(translation: Locale) { - return translation.node.InternalExpression; + getNodeLocale(locales: Locales) { + return locales.get((l) => l.node.InternalExpression); } - getStartExplanations(locale: Locale) { - return concretize(locale, locale.node.InternalExpression.start); + getStartExplanations(locales: Locales) { + return concretize( + locales, + locales.get((l) => l.node.InternalExpression.start) + ); } getGlyphs() { diff --git a/src/basis/Iteration.ts b/src/basis/Iteration.ts index 26dd81a6c..27ede10cf 100644 --- a/src/basis/Iteration.ts +++ b/src/basis/Iteration.ts @@ -1,5 +1,4 @@ import Purpose from '../concepts/Purpose'; -import type Locale from '../locale/Locale'; import concretize from '../locale/concretize'; import Glyphs from '../lore/Glyphs'; import AnyType from '../nodes/AnyType'; @@ -23,6 +22,7 @@ import Next from '@runtime/Next'; import Start from '@runtime/Start'; import type Step from '@runtime/Step'; import Value from '../values/Value'; +import type Locales from '../locale/Locales'; const IterationState = 'state'; @@ -218,23 +218,26 @@ export class Iteration extends Expression { return this; } - getNodeLocale(translation: Locale) { - return translation.node.Iteration; + getNodeLocale(locales: Locales) { + return locales.get((l) => l.node.Iteration); } - getStartExplanations(locale: Locale) { - return concretize(locale, locale.node.Iteration.start); + getStartExplanations(locales: Locales) { + return concretize( + locales, + locales.get((l) => l.node.Iteration.start) + ); } getFinishExplanations( - locale: Locale, + locales: Locales, context: Context, evaluator: Evaluator ) { return concretize( - locale, - locale.node.Iteration.finish, - this.getValueIfDefined(locale, context, evaluator) + locales, + locales.get((l) => l.node.Iteration.finish), + this.getValueIfDefined(locales, context, evaluator) ); } diff --git a/src/basis/ListBasis.ts b/src/basis/ListBasis.ts index ff58954ed..cb7b01511 100644 --- a/src/basis/ListBasis.ts +++ b/src/basis/ListBasis.ts @@ -20,7 +20,6 @@ import { getDocLocales } from '@locale/getDocLocales'; import { getNameLocales } from '@locale/getNameLocales'; import TypeVariable from '@nodes/TypeVariable'; import type Expression from '../nodes/Expression'; -import type Locale from '../locale/Locale'; import NoneLiteral from '../nodes/NoneLiteral'; import NoneValue from '@values/NoneValue'; import { Iteration } from './Iteration'; @@ -34,8 +33,9 @@ import InternalExpression from './InternalExpression'; import ConversionException from '@values/ConversionException'; import ExceptionValue from '@values/ExceptionValue'; import SetType from '../nodes/SetType'; +import type Locales from '../locale/Locales'; -export default function bootstrapList(locales: Locale[]) { +export default function bootstrapList(locales: Locales) { const ListTypeVarNames = getNameLocales( locales, (locale) => locale.basis.List.kind diff --git a/src/basis/MapBasis.ts b/src/basis/MapBasis.ts index 3e252412c..7a346248f 100644 --- a/src/basis/MapBasis.ts +++ b/src/basis/MapBasis.ts @@ -16,7 +16,6 @@ import TypeVariable from '@nodes/TypeVariable'; import type Evaluation from '@runtime/Evaluation'; import type Value from '@values/Value'; import type Expression from '../nodes/Expression'; -import type Locale from '../locale/Locale'; import { createFunction, createInputs } from '../locale/Locale'; import { Iteration } from './Iteration'; import NumberType from '../nodes/NumberType'; @@ -25,8 +24,9 @@ import TextType from '../nodes/TextType'; import SetType from '../nodes/SetType'; import ListType from '../nodes/ListType'; import AnyType from '../nodes/AnyType'; +import type Locales from '../locale/Locales'; -export default function bootstrapMap(locales: Locale[]) { +export default function bootstrapMap(locales: Locales) { const KeyTypeVariableNames = getNameLocales( locales, (locale) => locale.basis.Map.key diff --git a/src/basis/NoneBasis.ts b/src/basis/NoneBasis.ts index 6e1cbebf1..fbc6890d6 100644 --- a/src/basis/NoneBasis.ts +++ b/src/basis/NoneBasis.ts @@ -13,10 +13,11 @@ import type Expression from '../nodes/Expression'; import type Locale from '../locale/Locale'; import type { FunctionText, NameAndDoc } from '../locale/Locale'; import TextType from '../nodes/TextType'; +import type Locales from '../locale/Locales'; -export default function bootstrapNone(locales: Locale[]) { +export default function bootstrapNone(locales: Locales) { function createNoneFunction( - locales: Locale[], + locales: Locales, text: (locale: Locale) => FunctionText, expression: ( requestor: Expression, diff --git a/src/basis/NumberBasis.ts b/src/basis/NumberBasis.ts index f4ac84250..0f76f932a 100644 --- a/src/basis/NumberBasis.ts +++ b/src/basis/NumberBasis.ts @@ -25,8 +25,9 @@ import type Locale from '../locale/Locale'; import type { FunctionText, NameAndDoc } from '../locale/Locale'; import ListType from '../nodes/ListType'; import AnyType from '../nodes/AnyType'; +import type Locales from '../locale/Locales'; -export default function bootstrapNumber(locales: Locale[]) { +export default function bootstrapNumber(locales: Locales) { const subtractNames = getNameLocales( locales, (locale) => locale.basis.Number.function.subtract.inputs[0].names diff --git a/src/basis/SetBasis.ts b/src/basis/SetBasis.ts index 785066ff7..fb22bb246 100644 --- a/src/basis/SetBasis.ts +++ b/src/basis/SetBasis.ts @@ -15,7 +15,6 @@ import { getDocLocales } from '@locale/getDocLocales'; import { getNameLocales } from '@locale/getNameLocales'; import TypeVariable from '@nodes/TypeVariable'; import type Expression from '../nodes/Expression'; -import type Locale from '../locale/Locale'; import { createBind, createFunction, createInputs } from '../locale/Locale'; import { Iteration } from './Iteration'; import NumberType from '../nodes/NumberType'; @@ -23,8 +22,9 @@ import NumberValue from '@values/NumberValue'; import ListType from '../nodes/ListType'; import TextType from '../nodes/TextType'; import AnyType from '../nodes/AnyType'; +import type Locales from '../locale/Locales'; -export default function bootstrapSet(locales: Locale[]) { +export default function bootstrapSet(locales: Locales) { const SetTypeVariableNames = getNameLocales( locales, (locale) => locale.basis.Set.kind diff --git a/src/basis/StructureBasis.ts b/src/basis/StructureBasis.ts index 72d9d9b65..b615b60bb 100644 --- a/src/basis/StructureBasis.ts +++ b/src/basis/StructureBasis.ts @@ -2,7 +2,6 @@ import StructureDefinition from '@nodes/StructureDefinition'; import Block, { BlockKind } from '@nodes/Block'; import { getDocLocales } from '@locale/getDocLocales'; import { getNameLocales } from '@locale/getNameLocales'; -import type Locale from '../locale/Locale'; import { createBasisConversion, createBasisFunction } from './Basis'; import BoolValue from '@values/BoolValue'; import BooleanType from '../nodes/BooleanType'; @@ -13,8 +12,9 @@ import Value from '../values/Value'; import type StructureValue from '../values/StructureValue'; import TextType from '../nodes/TextType'; import TextValue from '../values/TextValue'; +import type Locales from '../locale/Locales'; -export default function bootstrapStructure(locales: Locale[]) { +export default function bootstrapStructure(locales: Locales) { return StructureDefinition.make( getDocLocales(locales, (locale) => locale.basis.Structure.doc), getNameLocales(locales, (locale) => locale.basis.Structure.name), diff --git a/src/basis/TableBasis.ts b/src/basis/TableBasis.ts index 484ea5dce..406c00561 100644 --- a/src/basis/TableBasis.ts +++ b/src/basis/TableBasis.ts @@ -10,7 +10,6 @@ import type Names from '@nodes/Names'; import { getInputLocales as getInputLocales } from '@locale/getInputLocales'; import { getDocLocales } from '@locale/getDocLocales'; import { getNameLocales } from '@locale/getNameLocales'; -import type Locale from '../locale/Locale'; import type Type from '../nodes/Type'; import TableType from '../nodes/TableType'; import TableValue from '../values/TableValue'; @@ -25,8 +24,9 @@ import TextValue from '../values/TextValue'; import TypeVariables from '../nodes/TypeVariables'; import TypeVariable from '../nodes/TypeVariable'; import AnyType from '../nodes/AnyType'; +import type Locales from '../locale/Locales'; -export default function bootstrapTable(locales: Locale[]) { +export default function bootstrapTable(locales: Locales) { /** This type variable represents the StructureDefinition of a row. */ const RowTypeVariable = new TypeVariable( getNameLocales(locales, (locale) => locale.basis.Table.row) @@ -135,7 +135,7 @@ export default function bootstrapTable(locales: Locale[]) { TableType.make(), TextType.make(), (requestor: Expression, table: TableValue) => - new TextValue(requestor, table.toWordplay([])) + new TextValue(requestor, table.toWordplay(locales)) ), ], BlockKind.Structure diff --git a/src/basis/TextBasis.ts b/src/basis/TextBasis.ts index acbe2b425..0f6cc0bfa 100644 --- a/src/basis/TextBasis.ts +++ b/src/basis/TextBasis.ts @@ -17,8 +17,9 @@ import type Locale from '../locale/Locale'; import type { FunctionText, NameAndDoc } from '../locale/Locale'; import ListType from '../nodes/ListType'; import AnyType from '../nodes/AnyType'; +import type Locales from '../locale/Locales'; -export default function bootstrapText(locales: Locale[]) { +export default function bootstrapText(locales: Locales) { function createBinaryTextFunction( functionText: (locale: Locale) => FunctionText, fun: ( diff --git a/src/components/annotations/Annotations.svelte b/src/components/annotations/Annotations.svelte index de314b5e6..0f15bd36c 100644 --- a/src/components/annotations/Annotations.svelte +++ b/src/components/annotations/Annotations.svelte @@ -20,7 +20,7 @@ import type Markup from '../../nodes/Markup'; import concretize from '../../locale/concretize'; import type Source from '../../nodes/Source'; - import { locale, locales } from '../../db/Database'; + import { locales } from '../../db/Database'; export let project: Project; export let evaluator: Evaluator; @@ -55,23 +55,25 @@ { node: node, element: view, - messages: $evaluation?.step - ? $locales.map((locale) => - ($evaluation?.step as Step).getExplanations( - locale, + messages: [ + $evaluation?.step + ? ($evaluation?.step as Step).getExplanations( + $locales, evaluator ) - ) - : evaluator.steppedToNode() && evaluator.isDone() - ? $locales.map((locale) => - concretize( - locale, - locale.node.Program.unevaluated + : evaluator.steppedToNode() && + evaluator.isDone() + ? concretize( + $locales, + $locales.get( + (l) => l.node.Program.unevaluated + ) ) - ) - : $locales.map((locale) => - concretize(locale, locale.node.Program.done) - ), + : concretize( + $locales, + $locales.get((l) => l.node.Program.done) + ), + ], kind: 'step', }, ]; @@ -93,17 +95,17 @@ { node: primary.node, element: getNodeView(primary.node), - messages: $locales.map((locale) => + messages: [ primary.explanation( - locale, + $locales, project.getNodeContext( primary.node ) ?? project.getContext( project.getMain() ) - ) - ), + ), + ], kind: conflict.isMinor() ? ('minor' as const) : ('primary' as const), @@ -116,14 +118,14 @@ { node: secondary.node, element: getNodeView(secondary.node), - messages: $locales.map((locale) => + messages: [ secondary.explanation( - locale, + $locales, project.getNodeContext( secondary.node ) - ) - ), + ), + ], kind: 'secondary' as const, }, ] @@ -188,7 +190,7 @@ -
+
l.ui.conflicts.label)}> {#each Array.from(annotationsByNode.values()) as annotations, index} {/each} diff --git a/src/components/app/CreatorView.svelte b/src/components/app/CreatorView.svelte index c5a1a342c..63ad55bad 100644 --- a/src/components/app/CreatorView.svelte +++ b/src/components/app/CreatorView.svelte @@ -1,6 +1,6 @@
- -

{$locale.ui.widget.loading.message}

+ l.ui.widget.loading.message)} large /> +

{$locales.get((l) => l.ui.widget.loading.message)}