Move lib/i18n/translate to lib/translate

* This restores tree shaking
This commit is contained in:
Henrik Giesel 2021-10-04 02:34:03 +02:00
parent 4083f16848
commit 8a839a844e
59 changed files with 91 additions and 78 deletions

View file

@ -1,5 +1,5 @@
licenses.json licenses.json
vendor vendor
lib/i18n/translate.ts lib/translate.ts
lib/i18n/modules.ts lib/i18n/modules.ts
backend_proto.d.ts backend_proto.d.ts

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import NotetypeSelector from "./NotetypeSelector.svelte"; import NotetypeSelector from "./NotetypeSelector.svelte";
import Mapper from "./Mapper.svelte"; import Mapper from "./Mapper.svelte";
import { ChangeNotetypeState, MapContext } from "./lib"; import { ChangeNotetypeState, MapContext } from "./lib";

View file

@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import MapperRow from "./MapperRow.svelte"; import MapperRow from "./MapperRow.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { ChangeNotetypeState, MapContext } from "./lib"; import { ChangeNotetypeState, MapContext } from "./lib";
import { slide } from "svelte/transition"; import { slide } from "svelte/transition";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import type { ChangeNotetypeState } from "./lib"; import type { ChangeNotetypeState } from "./lib";
import { withButton } from "../components/helpers"; import { withButton } from "../components/helpers";

View file

@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { Scheduler } from "../lib/proto"; import type { Scheduler } from "../lib/proto";
import { buildNextLearnMsg } from "./lib"; import { buildNextLearnMsg } from "./lib";
import { bridgeLink } from "../lib/bridgecommand"; import { bridgeLink } from "../lib/bridgecommand";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
export let info: Scheduler.CongratsInfoResponse; export let info: Scheduler.CongratsInfoResponse;

View file

@ -4,7 +4,7 @@
import { Scheduler } from "../lib/proto"; import { Scheduler } from "../lib/proto";
import { postRequest } from "../lib/postrequest"; import { postRequest } from "../lib/postrequest";
import { naturalUnit, unitAmount, unitName } from "../lib/time"; import { naturalUnit, unitAmount, unitName } from "../lib/time";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
export async function getCongratsInfo(): Promise<Scheduler.CongratsInfoResponse> { export async function getCongratsInfo(): Promise<Scheduler.CongratsInfoResponse> {
return Scheduler.CongratsInfoResponse.decode( return Scheduler.CongratsInfoResponse.decode(

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import TitledContainer from "./TitledContainer.svelte"; import TitledContainer from "./TitledContainer.svelte";
import Item from "../components/Item.svelte"; import Item from "../components/Item.svelte";
import SpinBoxRow from "./SpinBoxRow.svelte"; import SpinBoxRow from "./SpinBoxRow.svelte";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import TitledContainer from "./TitledContainer.svelte"; import TitledContainer from "./TitledContainer.svelte";
import Item from "../components/Item.svelte"; import Item from "../components/Item.svelte";
import SwitchRow from "./SwitchRow.svelte"; import SwitchRow from "./SwitchRow.svelte";

View file

@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import TitledContainer from "./TitledContainer.svelte"; import TitledContainer from "./TitledContainer.svelte";
import Item from "../components/Item.svelte"; import Item from "../components/Item.svelte";
import SwitchRow from "./SwitchRow.svelte"; import SwitchRow from "./SwitchRow.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import type { DeckOptionsState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckOptionsState; export let state: DeckOptionsState;

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import TooltipLabel from "./TooltipLabel.svelte"; import TooltipLabel from "./TooltipLabel.svelte";
import RevertButton from "./RevertButton.svelte"; import RevertButton from "./RevertButton.svelte";
import Row from "./Row.svelte"; import Row from "./Row.svelte";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { getContext } from "svelte"; import { getContext } from "svelte";
import { modalsKey } from "../components/context-keys"; import { modalsKey } from "../components/context-keys";
import type { DeckOptionsState, ConfigListEntry } from "./lib"; import type { DeckOptionsState, ConfigListEntry } from "./lib";

View file

@ -3,7 +3,7 @@
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import TitledContainer from "./TitledContainer.svelte"; import TitledContainer from "./TitledContainer.svelte";
import Item from "../components/Item.svelte"; import Item from "../components/Item.svelte";
import SpinBoxRow from "./SpinBoxRow.svelte"; import SpinBoxRow from "./SpinBoxRow.svelte";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import TitledContainer from "./TitledContainer.svelte"; import TitledContainer from "./TitledContainer.svelte";
import Item from "../components/Item.svelte"; import Item from "../components/Item.svelte";
import EnumSelectorRow from "./EnumSelectorRow.svelte"; import EnumSelectorRow from "./EnumSelectorRow.svelte";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import TitledContainer from "./TitledContainer.svelte"; import TitledContainer from "./TitledContainer.svelte";
import Item from "../components/Item.svelte"; import Item from "../components/Item.svelte";
import StepsInputRow from "./StepsInputRow.svelte"; import StepsInputRow from "./StepsInputRow.svelte";

View file

@ -11,7 +11,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import Warning from "./Warning.svelte"; import Warning from "./Warning.svelte";
import type { DeckOptionsState } from "./lib"; import type { DeckOptionsState } from "./lib";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
export let state: DeckOptionsState; export let state: DeckOptionsState;
export let api = {}; export let api = {};

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import type Dropdown from "bootstrap/js/dist/dropdown"; import type Dropdown from "bootstrap/js/dist/dropdown";
import WithDropdown from "../components/WithDropdown.svelte"; import WithDropdown from "../components/WithDropdown.svelte";
import DropdownMenu from "../components/DropdownMenu.svelte"; import DropdownMenu from "../components/DropdownMenu.svelte";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
import type { DeckOptionsState } from "./lib"; import type { DeckOptionsState } from "./lib";
import type Dropdown from "bootstrap/js/dist/dropdown"; import type Dropdown from "bootstrap/js/dist/dropdown";

View file

@ -7,7 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import Item from "../components/Item.svelte"; import Item from "../components/Item.svelte";
import SpinBoxRow from "./SpinBoxRow.svelte"; import SpinBoxRow from "./SpinBoxRow.svelte";
import SwitchRow from "./SwitchRow.svelte"; import SwitchRow from "./SwitchRow.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import type { DeckOptionsState } from "./lib"; import type { DeckOptionsState } from "./lib";
export let state: DeckOptionsState; export let state: DeckOptionsState;

View file

@ -1,7 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors // Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
export const reviewMixChoices = (): string[] => [ export const reviewMixChoices = (): string[] => [
tr.deckConfigReviewMixMixWithReviews(), tr.deckConfigReviewMixMixWithReviews(),

View file

@ -7,7 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import WithShortcut from "../components/WithShortcut.svelte"; import WithShortcut from "../components/WithShortcut.svelte";
import OnlyEditable from "./OnlyEditable.svelte"; import OnlyEditable from "./OnlyEditable.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { withButton } from "../components/helpers"; import { withButton } from "../components/helpers";
import { ellipseIcon } from "./icons"; import { ellipseIcon } from "./icons";
import { forEditorField } from "."; import { forEditorField } from ".";

View file

@ -11,7 +11,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import WithColorHelper from "./WithColorHelper.svelte"; import WithColorHelper from "./WithColorHelper.svelte";
import OnlyEditable from "./OnlyEditable.svelte"; import OnlyEditable from "./OnlyEditable.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { bridgeCommand } from "../lib/bridgecommand"; import { bridgeCommand } from "../lib/bridgecommand";
import { withButton } from "../components/helpers"; import { withButton } from "../components/helpers";
import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons"; import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons";

View file

@ -12,7 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import OnlyEditable from "./OnlyEditable.svelte"; import OnlyEditable from "./OnlyEditable.svelte";
import CommandIconButton from "./CommandIconButton.svelte"; import CommandIconButton from "./CommandIconButton.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { getListItem } from "../lib/dom"; import { getListItem } from "../lib/dom";
import { getCurrentField, execCommand } from "./helpers"; import { getCurrentField, execCommand } from "./helpers";
import { import {

View file

@ -7,7 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import ButtonGroupItem from "../components/ButtonGroupItem.svelte"; import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
import CommandIconButton from "./CommandIconButton.svelte"; import CommandIconButton from "./CommandIconButton.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { import {
boldIcon, boldIcon,
italicIcon, italicIcon,

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import ButtonGroup from "../components/ButtonGroup.svelte"; import ButtonGroup from "../components/ButtonGroup.svelte";
import ButtonGroupItem from "../components/ButtonGroupItem.svelte"; import ButtonGroupItem from "../components/ButtonGroupItem.svelte";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import ButtonGroup from "../components/ButtonGroup.svelte"; import ButtonGroup from "../components/ButtonGroup.svelte";
import ButtonGroupItem from "../components/ButtonGroupItem.svelte"; import ButtonGroupItem from "../components/ButtonGroupItem.svelte";

View file

@ -7,7 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import ButtonGroupItem from "../components/ButtonGroupItem.svelte"; import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
import IconButton from "../components/IconButton.svelte"; import IconButton from "../components/IconButton.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { inlineIcon, blockIcon } from "./icons"; import { inlineIcon, blockIcon } from "./icons";
export let activeImage: HTMLImageElement; export let activeImage: HTMLImageElement;

View file

@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { bridgeCommand } from "../lib/bridgecommand"; import { bridgeCommand } from "../lib/bridgecommand";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { withButton } from "../components/helpers"; import { withButton } from "../components/helpers";
import ButtonGroup from "../components/ButtonGroup.svelte"; import ButtonGroup from "../components/ButtonGroup.svelte";

View file

@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { bridgeCommand } from "../lib/bridgecommand"; import { bridgeCommand } from "../lib/bridgecommand";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { withButton } from "../components/helpers"; import { withButton } from "../components/helpers";
import WithShortcut from "../components/WithShortcut.svelte"; import WithShortcut from "../components/WithShortcut.svelte";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { bridgeCommand } from "../lib/bridgecommand"; import { bridgeCommand } from "../lib/bridgecommand";
import { fieldFocusedKey, inCodableKey } from "./context-keys"; import { fieldFocusedKey, inCodableKey } from "./context-keys";

View file

@ -2,7 +2,7 @@
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { EditorField } from "./editor-field"; import type { EditorField } from "./editor-field";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { registerShortcut } from "../lib/shortcuts"; import { registerShortcut } from "../lib/shortcuts";
import { bridgeCommand } from "./lib"; import { bridgeCommand } from "./lib";
import { appendInParentheses } from "./helpers"; import { appendInParentheses } from "./helpers";

View file

@ -13,7 +13,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import GraphRangeRadios from "./GraphRangeRadios.svelte"; import GraphRangeRadios from "./GraphRangeRadios.svelte";
import TableData from "./TableData.svelte"; import TableData from "./TableData.svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { RevlogRange, GraphRange } from "./graph-helpers"; import { RevlogRange, GraphRange } from "./graph-helpers";
import type { TableDatum, SearchEventMap } from "./graph-helpers"; import type { TableDatum, SearchEventMap } from "./graph-helpers";
import type { HistogramData } from "./histogram-graph"; import type { HistogramData } from "./histogram-graph";

View file

@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import type { Stats } from "../lib/proto"; import type { Stats } from "../lib/proto";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import Graph from "./Graph.svelte"; import Graph from "./Graph.svelte";
import InputBox from "./InputBox.svelte"; import InputBox from "./InputBox.svelte";

View file

@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
import type { Stats } from "../lib/proto"; import type { Stats } from "../lib/proto";
import type { PreferenceStore } from "../sveltelib/preferences"; import type { PreferenceStore } from "../sveltelib/preferences";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import Graph from "./Graph.svelte"; import Graph from "./Graph.svelte";
import InputBox from "./InputBox.svelte"; import InputBox from "./InputBox.svelte";

View file

@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
import type { Stats } from "../lib/proto"; import type { Stats } from "../lib/proto";
import type { PreferenceStore } from "../sveltelib/preferences"; import type { PreferenceStore } from "../sveltelib/preferences";
import { tr as trI18n } from "../lib/i18n"; import * as translate from "../lib/translate";
import { defaultGraphBounds } from "./graph-helpers"; import { defaultGraphBounds } from "./graph-helpers";
import type { SearchEventMap } from "./graph-helpers"; import type { SearchEventMap } from "./graph-helpers";
import { gatherData, renderCards } from "./card-counts"; import { gatherData, renderCards } from "./card-counts";
@ -35,8 +35,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
tableData = renderCards(svg as any, bounds, graphData); tableData = renderCards(svg as any, bounds, graphData);
} }
const label = trI18n.statisticsCountsSeparateSuspendedBuriedCards(); const label = translate.statisticsCountsSeparateSuspendedBuriedCards();
const total = trI18n.statisticsCountsTotalCards(); const total = translate.statisticsCountsTotalCards();
</script> </script>
<Graph title={graphData.title}> <Graph title={graphData.title}>

View file

@ -7,7 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import type { PreferenceStore } from "../sveltelib/preferences"; import type { PreferenceStore } from "../sveltelib/preferences";
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import HistogramGraph from "./HistogramGraph.svelte"; import HistogramGraph from "./HistogramGraph.svelte";
import Graph from "./Graph.svelte"; import Graph from "./Graph.svelte";

View file

@ -14,7 +14,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import TableData from "./TableData.svelte"; import TableData from "./TableData.svelte";
import type { PreferenceStore } from "../sveltelib/preferences"; import type { PreferenceStore } from "../sveltelib/preferences";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import type { HistogramData } from "./histogram-graph"; import type { HistogramData } from "./histogram-graph";
import { GraphRange, RevlogRange } from "./graph-helpers"; import { GraphRange, RevlogRange } from "./graph-helpers";
import type { TableDatum, SearchEventMap } from "./graph-helpers"; import type { TableDatum, SearchEventMap } from "./graph-helpers";

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { RevlogRange, GraphRange } from "./graph-helpers"; import { RevlogRange, GraphRange } from "./graph-helpers";
import { timeSpan, MONTH, YEAR } from "../lib/time"; import { timeSpan, MONTH, YEAR } from "../lib/time";

View file

@ -12,7 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import HoverColumns from "./HoverColumns.svelte"; import HoverColumns from "./HoverColumns.svelte";
import type { Stats } from "../lib/proto"; import type { Stats } from "../lib/proto";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { defaultGraphBounds, RevlogRange, GraphRange } from "./graph-helpers"; import { defaultGraphBounds, RevlogRange, GraphRange } from "./graph-helpers";
import { renderHours } from "./hours"; import { renderHours } from "./hours";

View file

@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import TableData from "./TableData.svelte"; import TableData from "./TableData.svelte";
import { timeSpan, MONTH } from "../lib/time"; import { timeSpan, MONTH } from "../lib/time";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import type { Stats } from "../lib/proto"; import type { Stats } from "../lib/proto";
import type { PreferenceStore } from "../sveltelib/preferences"; import type { PreferenceStore } from "../sveltelib/preferences";
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";

View file

@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import type { GraphBounds } from "./graph-helpers"; import type { GraphBounds } from "./graph-helpers";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
export let bounds: GraphBounds; export let bounds: GraphBounds;

View file

@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import InputBox from "./InputBox.svelte"; import InputBox from "./InputBox.svelte";
import type { Writable } from "svelte/store"; import type { Writable } from "svelte/store";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { RevlogRange, daysToRevlogRange } from "./graph-helpers"; import { RevlogRange, daysToRevlogRange } from "./graph-helpers";
enum SearchRange { enum SearchRange {

View file

@ -13,7 +13,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import HoverColumns from "./HoverColumns.svelte"; import HoverColumns from "./HoverColumns.svelte";
import type { Stats } from "../lib/proto"; import type { Stats } from "../lib/proto";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { defaultGraphBounds, RevlogRange, GraphRange } from "./graph-helpers"; import { defaultGraphBounds, RevlogRange, GraphRange } from "./graph-helpers";
import type { TableDatum } from "./graph-helpers"; import type { TableDatum } from "./graph-helpers";
import { gatherData, renderReviews } from "./reviews"; import { gatherData, renderReviews } from "./reviews";

View file

@ -19,7 +19,7 @@ import {
import type { Bin } from "d3"; import type { Bin } from "d3";
import type { HistogramData } from "./histogram-graph"; import type { HistogramData } from "./histogram-graph";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { dayLabel } from "../lib/time"; import { dayLabel } from "../lib/time";
import { GraphRange } from "./graph-helpers"; import { GraphRange } from "./graph-helpers";
import type { TableDatum, SearchDispatch } from "./graph-helpers"; import type { TableDatum, SearchDispatch } from "./graph-helpers";

View file

@ -18,7 +18,7 @@ import {
sum, sum,
} from "d3"; } from "d3";
import { Stats } from "../lib/proto"; import { Stats } from "../lib/proto";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { showTooltip, hideTooltip } from "./tooltip"; import { showTooltip, hideTooltip } from "./tooltip";
import { import {
GraphBounds, GraphBounds,

View file

@ -29,7 +29,8 @@ import {
SearchDispatch, SearchDispatch,
} from "./graph-helpers"; } from "./graph-helpers";
import { clickableClass } from "./graph-styles"; import { clickableClass } from "./graph-styles";
import { tr, weekdayLabel, toLocaleString } from "../lib/i18n"; import { weekdayLabel, toLocaleString } from "../lib/i18n";
import * as tr from "../lib/translate";
export interface GraphData { export interface GraphData {
// indexed by day, where day is relative to today // indexed by day, where day is relative to today

View file

@ -6,7 +6,7 @@
@typescript-eslint/no-explicit-any: "off", @typescript-eslint/no-explicit-any: "off",
*/ */
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { CardQueue, CardType } from "../lib/cards"; import { CardQueue, CardType } from "../lib/cards";
import type { Stats, Cards } from "../lib/proto"; import type { Stats, Cards } from "../lib/proto";
import { import {

View file

@ -16,7 +16,7 @@ import {
interpolateRdYlGn, interpolateRdYlGn,
} from "d3"; } from "d3";
import type { Bin, ScaleLinear } from "d3"; import type { Bin, ScaleLinear } from "d3";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { CardType } from "../lib/cards"; import { CardType } from "../lib/cards";
import type { HistogramData } from "./histogram-graph"; import type { HistogramData } from "./histogram-graph";
import type { TableDatum, SearchDispatch } from "./graph-helpers"; import type { TableDatum, SearchDispatch } from "./graph-helpers";

View file

@ -17,7 +17,7 @@ import {
interpolateGreens, interpolateGreens,
} from "d3"; } from "d3";
import type { Bin } from "d3"; import type { Bin } from "d3";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { CardQueue } from "../lib/cards"; import { CardQueue } from "../lib/cards";
import type { HistogramData } from "./histogram-graph"; import type { HistogramData } from "./histogram-graph";
import { dayLabel } from "../lib/time"; import { dayLabel } from "../lib/time";

View file

@ -21,7 +21,7 @@ import {
curveBasis, curveBasis,
} from "d3"; } from "d3";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { showTooltip, hideTooltip } from "./tooltip"; import { showTooltip, hideTooltip } from "./tooltip";
import { import {
GraphBounds, GraphBounds,

View file

@ -18,7 +18,7 @@ import {
interpolateBlues, interpolateBlues,
} from "d3"; } from "d3";
import type { Bin } from "d3"; import type { Bin } from "d3";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import { timeSpan } from "../lib/time"; import { timeSpan } from "../lib/time";
import { CardType } from "../lib/cards"; import { CardType } from "../lib/cards";
import type { HistogramData } from "./histogram-graph"; import type { HistogramData } from "./histogram-graph";

View file

@ -32,7 +32,7 @@ import {
} from "d3"; } from "d3";
import type { Bin } from "d3"; import type { Bin } from "d3";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
import type { TableDatum } from "./graph-helpers"; import type { TableDatum } from "./graph-helpers";
import { GraphBounds, setDataAvailable, GraphRange } from "./graph-helpers"; import { GraphBounds, setDataAvailable, GraphRange } from "./graph-helpers";
import { showTooltip, hideTooltip } from "./tooltip"; import { showTooltip, hideTooltip } from "./tooltip";

View file

@ -3,7 +3,7 @@
import { Stats } from "../lib/proto"; import { Stats } from "../lib/proto";
import { studiedToday } from "../lib/time"; import { studiedToday } from "../lib/time";
import { tr } from "../lib/i18n"; import * as tr from "../lib/translate";
export interface TodayData { export interface TodayData {
title: string; title: string;

View file

@ -17,7 +17,7 @@ py_binary(
], ],
) )
_i18n_generated = [ _i18n_generated = [
"i18n/translate.ts", "translate.ts",
"i18n/modules.ts", "i18n/modules.ts",
] ]
@ -46,7 +46,7 @@ typescript(
exclude = _generated, exclude = _generated,
generated = [ generated = [
":backend_proto.d.ts", ":backend_proto.d.ts",
":i18n/translate.ts", ":translate.ts",
":i18n/modules.ts", ":i18n/modules.ts",
], ],
deps = [ deps = [

View file

@ -17,7 +17,12 @@ class Variable(TypedDict):
def methods() -> str: def methods() -> str:
out = [ 'import { translate } from "./bundles";' ] out = [ """import type { FluentVariable } from "@fluent/bundle";
import { getMessage } from "./i18n";
function translate(key: string, args: Record<string, FluentVariable> = {}): string {
return getMessage(key, args) ?? `missing key: ${key}`;
}""" ]
for module in modules: for module in modules:
for translation in module["translations"]: for translation in module["translations"]:
key = stringcase.camelcase(translation["key"].replace("-", "_")) key = stringcase.camelcase(translation["key"].replace("-", "_"))

View file

@ -2,8 +2,7 @@
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { FluentNumber } from "@fluent/bundle"; import { FluentNumber } from "@fluent/bundle";
import type { FluentBundle } from "@fluent/bundle"; import type { FluentBundle, FluentVariable } from "@fluent/bundle";
type RecordVal = number | string | FluentNumber;
let bundles: FluentBundle[] = []; let bundles: FluentBundle[] = [];
@ -15,26 +14,33 @@ export function firstLanguage(): string {
return bundles[0].locales[0]; return bundles[0].locales[0];
} }
function formatNumbers(args: Record<string, RecordVal>): void { function toFluentNumber(num: number): FluentNumber {
for (const key of Object.keys(args)) { return new FluentNumber(num, {
if (typeof args[key] === "number") { maximumFractionDigits: 2,
args[key] = new FluentNumber(args[key] as number, { });
maximumFractionDigits: 2,
});
}
}
} }
export function translate(key: string, args?: Record<string, RecordVal>): string { function formatArgs(
if (args) { args: Record<string, FluentVariable>
formatNumbers(args); ): Record<string, FluentVariable> {
} return Object.fromEntries(
Object.entries(args).map(([key, value]) => [
key,
typeof value === "number" ? toFluentNumber(value) : value,
])
);
}
export function getMessage(
key: string,
args: Record<string, FluentVariable> = {}
): string | null {
for (const bundle of bundles) { for (const bundle of bundles) {
const msg = bundle.getMessage(key); const msg = bundle.getMessage(key);
if (msg && msg.value) { if (msg && msg.value) {
return bundle.formatPattern(msg.value, args); return bundle.formatPattern(msg.value, formatArgs(args));
} }
} }
return `missing key: ${key}`;
return null;
} }

View file

@ -1,3 +1,3 @@
export * from "./bundles";
export * from "./modules";
export * from "./utils"; export * from "./utils";
export * as tr from "./translate";
export { ModuleName } from "./modules";

View file

@ -1,7 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors // Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { tr } from "./i18n"; import * as tr from "./translate";
import { isApplePlatform } from "./platform"; import { isApplePlatform } from "./platform";
// those are the modifiers that Anki works with // those are the modifiers that Anki works with

View file

@ -1,7 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors // Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { tr } from "./i18n"; import * as tr from "./translate";
export const SECOND = 1.0; export const SECOND = 1.0;
export const MINUTE = 60.0 * SECOND; export const MINUTE = 60.0 * SECOND;

View file

@ -21,8 +21,9 @@
"lib": [ "lib": [
"es2017", "es2017",
"es2018.intl", "es2018.intl",
"es2019.array",
"es2018.promise", "es2018.promise",
"es2019.array",
"es2019.object",
"es2020.promise", "es2020.promise",
"es2019.string", "es2019.string",
"dom", "dom",