mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
Move lib/i18n/translate to lib/translate
* This restores tree shaking
This commit is contained in:
parent
4083f16848
commit
8a839a844e
59 changed files with 91 additions and 78 deletions
|
@ -1,5 +1,5 @@
|
|||
licenses.json
|
||||
vendor
|
||||
lib/i18n/translate.ts
|
||||
lib/translate.ts
|
||||
lib/i18n/modules.ts
|
||||
backend_proto.d.ts
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import NotetypeSelector from "./NotetypeSelector.svelte";
|
||||
import Mapper from "./Mapper.svelte";
|
||||
import { ChangeNotetypeState, MapContext } from "./lib";
|
||||
|
|
|
@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
-->
|
||||
<script lang="ts">
|
||||
import MapperRow from "./MapperRow.svelte";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { ChangeNotetypeState, MapContext } from "./lib";
|
||||
import { slide } from "svelte/transition";
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import type { ChangeNotetypeState } from "./lib";
|
||||
import { withButton } from "../components/helpers";
|
||||
|
||||
|
|
|
@ -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 { buildNextLearnMsg } from "./lib";
|
||||
import { bridgeLink } from "../lib/bridgecommand";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
export let info: Scheduler.CongratsInfoResponse;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import { Scheduler } from "../lib/proto";
|
||||
import { postRequest } from "../lib/postrequest";
|
||||
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> {
|
||||
return Scheduler.CongratsInfoResponse.decode(
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import TitledContainer from "./TitledContainer.svelte";
|
||||
import Item from "../components/Item.svelte";
|
||||
import SpinBoxRow from "./SpinBoxRow.svelte";
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import TitledContainer from "./TitledContainer.svelte";
|
||||
import Item from "../components/Item.svelte";
|
||||
import SwitchRow from "./SwitchRow.svelte";
|
||||
|
|
|
@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import TitledContainer from "./TitledContainer.svelte";
|
||||
import Item from "../components/Item.svelte";
|
||||
import SwitchRow from "./SwitchRow.svelte";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import type { DeckOptionsState } from "./lib";
|
||||
|
||||
export let state: DeckOptionsState;
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import TooltipLabel from "./TooltipLabel.svelte";
|
||||
import RevertButton from "./RevertButton.svelte";
|
||||
import Row from "./Row.svelte";
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { getContext } from "svelte";
|
||||
import { modalsKey } from "../components/context-keys";
|
||||
import type { DeckOptionsState, ConfigListEntry } from "./lib";
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import TitledContainer from "./TitledContainer.svelte";
|
||||
import Item from "../components/Item.svelte";
|
||||
import SpinBoxRow from "./SpinBoxRow.svelte";
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import TitledContainer from "./TitledContainer.svelte";
|
||||
import Item from "../components/Item.svelte";
|
||||
import EnumSelectorRow from "./EnumSelectorRow.svelte";
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import TitledContainer from "./TitledContainer.svelte";
|
||||
import Item from "../components/Item.svelte";
|
||||
import StepsInputRow from "./StepsInputRow.svelte";
|
||||
|
|
|
@ -11,7 +11,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import Warning from "./Warning.svelte";
|
||||
|
||||
import type { DeckOptionsState } from "./lib";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
export let state: DeckOptionsState;
|
||||
export let api = {};
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import type Dropdown from "bootstrap/js/dist/dropdown";
|
||||
import WithDropdown from "../components/WithDropdown.svelte";
|
||||
import DropdownMenu from "../components/DropdownMenu.svelte";
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
import type { DeckOptionsState } from "./lib";
|
||||
import type Dropdown from "bootstrap/js/dist/dropdown";
|
||||
|
|
|
@ -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 SpinBoxRow from "./SpinBoxRow.svelte";
|
||||
import SwitchRow from "./SwitchRow.svelte";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import type { DeckOptionsState } from "./lib";
|
||||
|
||||
export let state: DeckOptionsState;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// 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[] => [
|
||||
tr.deckConfigReviewMixMixWithReviews(),
|
||||
|
|
|
@ -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 OnlyEditable from "./OnlyEditable.svelte";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { withButton } from "../components/helpers";
|
||||
import { ellipseIcon } from "./icons";
|
||||
import { forEditorField } from ".";
|
||||
|
|
|
@ -11,7 +11,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import WithColorHelper from "./WithColorHelper.svelte";
|
||||
import OnlyEditable from "./OnlyEditable.svelte";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { bridgeCommand } from "../lib/bridgecommand";
|
||||
import { withButton } from "../components/helpers";
|
||||
import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons";
|
||||
|
|
|
@ -12,7 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import OnlyEditable from "./OnlyEditable.svelte";
|
||||
import CommandIconButton from "./CommandIconButton.svelte";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { getListItem } from "../lib/dom";
|
||||
import { getCurrentField, execCommand } from "./helpers";
|
||||
import {
|
||||
|
|
|
@ -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 CommandIconButton from "./CommandIconButton.svelte";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import {
|
||||
boldIcon,
|
||||
italicIcon,
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="typescript">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="typescript">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
||||
|
|
|
@ -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 IconButton from "../components/IconButton.svelte";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { inlineIcon, blockIcon } from "./icons";
|
||||
|
||||
export let activeImage: HTMLImageElement;
|
||||
|
|
|
@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
-->
|
||||
<script lang="typescript">
|
||||
import { bridgeCommand } from "../lib/bridgecommand";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { withButton } from "../components/helpers";
|
||||
|
||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||
|
|
|
@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
-->
|
||||
<script lang="typescript">
|
||||
import { bridgeCommand } from "../lib/bridgecommand";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { withButton } from "../components/helpers";
|
||||
|
||||
import WithShortcut from "../components/WithShortcut.svelte";
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="typescript">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { bridgeCommand } from "../lib/bridgecommand";
|
||||
import { fieldFocusedKey, inCodableKey } from "./context-keys";
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import type { EditorField } from "./editor-field";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { registerShortcut } from "../lib/shortcuts";
|
||||
import { bridgeCommand } from "./lib";
|
||||
import { appendInParentheses } from "./helpers";
|
||||
|
|
|
@ -13,7 +13,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import GraphRangeRadios from "./GraphRangeRadios.svelte";
|
||||
import TableData from "./TableData.svelte";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { RevlogRange, GraphRange } from "./graph-helpers";
|
||||
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
||||
import type { HistogramData } from "./histogram-graph";
|
||||
|
|
|
@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
-->
|
||||
<script lang="typescript">
|
||||
import type { Stats } from "../lib/proto";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
import Graph from "./Graph.svelte";
|
||||
import InputBox from "./InputBox.svelte";
|
||||
|
|
|
@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import { createEventDispatcher } from "svelte";
|
||||
import type { Stats } from "../lib/proto";
|
||||
import type { PreferenceStore } from "../sveltelib/preferences";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
import Graph from "./Graph.svelte";
|
||||
import InputBox from "./InputBox.svelte";
|
||||
|
|
|
@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import { createEventDispatcher } from "svelte";
|
||||
import type { Stats } from "../lib/proto";
|
||||
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 type { SearchEventMap } from "./graph-helpers";
|
||||
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);
|
||||
}
|
||||
|
||||
const label = trI18n.statisticsCountsSeparateSuspendedBuriedCards();
|
||||
const total = trI18n.statisticsCountsTotalCards();
|
||||
const label = translate.statisticsCountsSeparateSuspendedBuriedCards();
|
||||
const total = translate.statisticsCountsTotalCards();
|
||||
</script>
|
||||
|
||||
<Graph title={graphData.title}>
|
||||
|
|
|
@ -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 { createEventDispatcher } from "svelte";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
import HistogramGraph from "./HistogramGraph.svelte";
|
||||
import Graph from "./Graph.svelte";
|
||||
|
|
|
@ -14,7 +14,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import TableData from "./TableData.svelte";
|
||||
import type { PreferenceStore } from "../sveltelib/preferences";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import type { HistogramData } from "./histogram-graph";
|
||||
import { GraphRange, RevlogRange } from "./graph-helpers";
|
||||
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
||||
|
|
|
@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
|
|||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
-->
|
||||
<script lang="typescript">
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { RevlogRange, GraphRange } from "./graph-helpers";
|
||||
import { timeSpan, MONTH, YEAR } from "../lib/time";
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import HoverColumns from "./HoverColumns.svelte";
|
||||
|
||||
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 { renderHours } from "./hours";
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import TableData from "./TableData.svelte";
|
||||
|
||||
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 { PreferenceStore } from "../sveltelib/preferences";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
|
|
@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
-->
|
||||
<script lang="typescript">
|
||||
import type { GraphBounds } from "./graph-helpers";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
export let bounds: GraphBounds;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import InputBox from "./InputBox.svelte";
|
||||
|
||||
import type { Writable } from "svelte/store";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { RevlogRange, daysToRevlogRange } from "./graph-helpers";
|
||||
|
||||
enum SearchRange {
|
||||
|
|
|
@ -13,7 +13,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import HoverColumns from "./HoverColumns.svelte";
|
||||
|
||||
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 type { TableDatum } from "./graph-helpers";
|
||||
import { gatherData, renderReviews } from "./reviews";
|
||||
|
|
|
@ -19,7 +19,7 @@ import {
|
|||
import type { Bin } from "d3";
|
||||
import type { HistogramData } from "./histogram-graph";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { dayLabel } from "../lib/time";
|
||||
import { GraphRange } from "./graph-helpers";
|
||||
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||
|
|
|
@ -18,7 +18,7 @@ import {
|
|||
sum,
|
||||
} from "d3";
|
||||
import { Stats } from "../lib/proto";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { showTooltip, hideTooltip } from "./tooltip";
|
||||
import {
|
||||
GraphBounds,
|
||||
|
|
|
@ -29,7 +29,8 @@ import {
|
|||
SearchDispatch,
|
||||
} from "./graph-helpers";
|
||||
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 {
|
||||
// indexed by day, where day is relative to today
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
@typescript-eslint/no-explicit-any: "off",
|
||||
*/
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { CardQueue, CardType } from "../lib/cards";
|
||||
import type { Stats, Cards } from "../lib/proto";
|
||||
import {
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
interpolateRdYlGn,
|
||||
} 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 type { HistogramData } from "./histogram-graph";
|
||||
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
interpolateGreens,
|
||||
} from "d3";
|
||||
import type { Bin } from "d3";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { CardQueue } from "../lib/cards";
|
||||
import type { HistogramData } from "./histogram-graph";
|
||||
import { dayLabel } from "../lib/time";
|
||||
|
|
|
@ -21,7 +21,7 @@ import {
|
|||
curveBasis,
|
||||
} from "d3";
|
||||
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { showTooltip, hideTooltip } from "./tooltip";
|
||||
import {
|
||||
GraphBounds,
|
||||
|
|
|
@ -18,7 +18,7 @@ import {
|
|||
interpolateBlues,
|
||||
} from "d3";
|
||||
import type { Bin } from "d3";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
import { timeSpan } from "../lib/time";
|
||||
import { CardType } from "../lib/cards";
|
||||
import type { HistogramData } from "./histogram-graph";
|
||||
|
|
|
@ -32,7 +32,7 @@ import {
|
|||
} 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 { GraphBounds, setDataAvailable, GraphRange } from "./graph-helpers";
|
||||
import { showTooltip, hideTooltip } from "./tooltip";
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import { Stats } from "../lib/proto";
|
||||
import { studiedToday } from "../lib/time";
|
||||
import { tr } from "../lib/i18n";
|
||||
import * as tr from "../lib/translate";
|
||||
|
||||
export interface TodayData {
|
||||
title: string;
|
||||
|
|
|
@ -17,7 +17,7 @@ py_binary(
|
|||
],
|
||||
)
|
||||
_i18n_generated = [
|
||||
"i18n/translate.ts",
|
||||
"translate.ts",
|
||||
"i18n/modules.ts",
|
||||
]
|
||||
|
||||
|
@ -46,7 +46,7 @@ typescript(
|
|||
exclude = _generated,
|
||||
generated = [
|
||||
":backend_proto.d.ts",
|
||||
":i18n/translate.ts",
|
||||
":translate.ts",
|
||||
":i18n/modules.ts",
|
||||
],
|
||||
deps = [
|
||||
|
|
|
@ -17,7 +17,12 @@ class Variable(TypedDict):
|
|||
|
||||
|
||||
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 translation in module["translations"]:
|
||||
key = stringcase.camelcase(translation["key"].replace("-", "_"))
|
||||
|
|
|
@ -2,8 +2,7 @@
|
|||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import { FluentNumber } from "@fluent/bundle";
|
||||
import type { FluentBundle } from "@fluent/bundle";
|
||||
type RecordVal = number | string | FluentNumber;
|
||||
import type { FluentBundle, FluentVariable } from "@fluent/bundle";
|
||||
|
||||
let bundles: FluentBundle[] = [];
|
||||
|
||||
|
@ -15,26 +14,33 @@ export function firstLanguage(): string {
|
|||
return bundles[0].locales[0];
|
||||
}
|
||||
|
||||
function formatNumbers(args: Record<string, RecordVal>): void {
|
||||
for (const key of Object.keys(args)) {
|
||||
if (typeof args[key] === "number") {
|
||||
args[key] = new FluentNumber(args[key] as number, {
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
}
|
||||
}
|
||||
function toFluentNumber(num: number): FluentNumber {
|
||||
return new FluentNumber(num, {
|
||||
maximumFractionDigits: 2,
|
||||
});
|
||||
}
|
||||
|
||||
export function translate(key: string, args?: Record<string, RecordVal>): string {
|
||||
if (args) {
|
||||
formatNumbers(args);
|
||||
}
|
||||
function formatArgs(
|
||||
args: Record<string, FluentVariable>
|
||||
): 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) {
|
||||
const msg = bundle.getMessage(key);
|
||||
if (msg && msg.value) {
|
||||
return bundle.formatPattern(msg.value, args);
|
||||
return bundle.formatPattern(msg.value, formatArgs(args));
|
||||
}
|
||||
}
|
||||
return `missing key: ${key}`;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export * from "./bundles";
|
||||
export * from "./modules";
|
||||
export * from "./utils";
|
||||
export * as tr from "./translate";
|
||||
export { ModuleName } from "./modules";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// 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";
|
||||
|
||||
// those are the modifiers that Anki works with
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// 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 MINUTE = 60.0 * SECOND;
|
||||
|
|
|
@ -21,8 +21,9 @@
|
|||
"lib": [
|
||||
"es2017",
|
||||
"es2018.intl",
|
||||
"es2019.array",
|
||||
"es2018.promise",
|
||||
"es2019.array",
|
||||
"es2019.object",
|
||||
"es2020.promise",
|
||||
"es2019.string",
|
||||
"dom",
|
||||
|
|
Loading…
Reference in a new issue