Skip to content

Commit

Permalink
Fixed #485 Allow selection of language for output.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Jul 13, 2024
1 parent a8f6e30 commit d55f4a5
Show file tree
Hide file tree
Showing 105 changed files with 869 additions and 11,987 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Dates are in `YYYY-MM-DD` format and versions are in [semantic versioning](http:
- Fixed parsing bug that prevented complete parsing of the program.
- Fixed reactivity dependency bug that included evaluates in branch dependencies.
- Fixed selection of locale in evaluation.
- [#485](https://github.com/wordplaydev/wordplay/issues/485) Allow selection of language for output.

## 0.10.4 2024-07-08

Expand Down
8 changes: 4 additions & 4 deletions src/basis/Basis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import type TypeVariables from '@nodes/TypeVariables';
import type Docs from '@nodes/Docs';
import type Expression from '@nodes/Expression';
import Root from '../nodes/Root';
import type Locale from '../locale/Locale';
import type LocaleText from '../locale/LocaleText';
import createDefaultShares from '@runtime/createDefaultShares';
import type LanguageCode from '../locale/LanguageCode';
import bootstrapTable from './TableBasis';
import {
createInputs,
type FunctionText,
type NameAndDoc,
} from '../locale/Locale';
} from '../locale/LocaleText';
import { getDocLocales } from '../locale/getDocLocales';
import { getNameLocales } from '../locale/getNameLocales';
import bootstrapStructure from './StructureBasis';
Expand Down Expand Up @@ -165,7 +165,7 @@ export class Basis {

export function createBasisFunction(
locales: Locales,
text: (locale: Locale) => FunctionText<NameAndDoc[]>,
text: (locale: LocaleText) => FunctionText<NameAndDoc[]>,
typeVars: TypeVariables | undefined,
types: (Type | [Type, Expression])[],
output: Type,
Expand All @@ -183,7 +183,7 @@ export function createBasisFunction(

export function createEqualsFunction(
locales: Locales,
text: (locale: Locale) => FunctionText<NameAndDoc[]>,
text: (locale: LocaleText) => FunctionText<NameAndDoc[]>,
equal: boolean,
) {
return createBasisFunction(
Expand Down
36 changes: 18 additions & 18 deletions src/basis/BoolBasis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import { getDocLocales } from '@locale/getDocLocales';
import { getNameLocales } from '@locale/getNameLocales';
import Evaluation from '@runtime/Evaluation';
import type Expression from '../nodes/Expression';
import type Locale from '../locale/Locale';
import type { FunctionText, NameAndDoc } from '../locale/Locale';
import type LocaleText from '../locale/LocaleText';
import type { FunctionText, NameAndDoc } from '../locale/LocaleText';
import type Type from '../nodes/Type';
import type Locales from '../locale/Locales';

export default function bootstrapBool(locales: Locales) {
function createBooleanFunction(
text: (locale: Locale) => FunctionText<NameAndDoc[]>,
text: (locale: LocaleText) => FunctionText<NameAndDoc[]>,
inputs: Type[],
expression: (
requestor: Expression,
left: BoolValue,
right: BoolValue
) => BoolValue
right: BoolValue,
) => BoolValue,
) {
return createBasisFunction(
locales,
Expand All @@ -42,16 +42,16 @@ export default function bootstrapBool(locales: Locales) {
return evaluation.getValueOrTypeException(
requestor,
BooleanType.make(),
left instanceof Evaluation ? undefined : left
left instanceof Evaluation ? undefined : left,
);
if (!(right instanceof BoolValue))
return evaluation.getValueOrTypeException(
requestor,
BooleanType.make(),
right
right,
);
return expression(requestor, left, right);
}
},
);
}

Expand All @@ -66,12 +66,12 @@ export default function bootstrapBool(locales: Locales) {
createBooleanFunction(
(locale) => locale.basis.Boolean.function.and,
[BooleanType.make()],
(requestor, left, right) => left.and(requestor, right)
(requestor, left, right) => left.and(requestor, right),
),
createBooleanFunction(
(locale) => locale.basis.Boolean.function.or,
[BooleanType.make()],
(requestor, left, right) => left.or(requestor, right)
(requestor, left, right) => left.or(requestor, right),
),
createBasisFunction(
locales,
Expand All @@ -86,33 +86,33 @@ export default function bootstrapBool(locales: Locales) {
return evaluation.getValueOrTypeException(
requestor,
BooleanType.make(),
left
left,
);
return left.not(requestor);
}
},
),
createEqualsFunction(
locales,
(locale) => locale.basis.Boolean.function.equals,
true
true,
),
createEqualsFunction(
locales,
(locale) => locale.basis.Boolean.function.notequal,
false
false,
),
createBasisConversion(
getDocLocales(
locales,
(locale) => locale.basis.Boolean.conversion.text
(locale) => locale.basis.Boolean.conversion.text,
),
'?',
"''",
(requestor, val: Value) =>
new TextValue(requestor, val.toString())
new TextValue(requestor, val.toString()),
),
],
BlockKind.Structure
)
BlockKind.Structure,
),
);
}
4 changes: 2 additions & 2 deletions src/basis/Fonts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writable } from 'svelte/store';
import { OR_SYMBOL } from '@parser/Symbols';
import { Latin, LatinCyrillicGreek, type Script } from '../locale/Scripts';
import type Locale from '../locale/Locale';
import type LocaleText from '../locale/LocaleText';

export type FontWeight = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
export type FontWeightRange = { min: FontWeight; max: FontWeight };
Expand Down Expand Up @@ -410,7 +410,7 @@ export class FontManager {
);
}

loadLocales(locales: Locale[]) {
loadLocales(locales: LocaleText[]) {
for (const locale of locales) {
this.loadFace(locale.ui.font.app);
this.loadFace(locale.ui.font.code);
Expand Down
5 changes: 4 additions & 1 deletion src/basis/ListBasis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import type Expression from '../nodes/Expression';
import NoneLiteral from '../nodes/NoneLiteral';
import NoneValue from '@values/NoneValue';
import { Iteration } from './Iteration';
import { createFunction, createInputs as createInputs } from '../locale/Locale';
import {
createFunction,
createInputs as createInputs,
} from '../locale/LocaleText';
import ValueException from '../values/ValueException';
import FunctionDefinition from '../nodes/FunctionDefinition';
import Names from '../nodes/Names';
Expand Down
Loading

0 comments on commit d55f4a5

Please sign in to comment.