mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Refactor i18n (#1405)
Merging note: the typing changes were fixed in a separate PR. * Put rootDirs into subprojects - typings do not work for any ts or svelte files - if we set the 'rootDirs' in ts/tsconfig.json to '../bazel-bin/ts' and then inherit them from e.g. editor, the root will be changed to '../../bazel-bin/ts', however editor needs look in '../../bazel-bin/ts/editor' instead. * Rename i18n and i18n_helpers to i18n-generated and i18n - This way, we can restrict the awkwardness of importing files outside the ts directory within lib * Fix missing typing of i18n and backend_proto by adding back symlinks * Split up i18n-generated into i18n-{translate,modules} * Change i18n from singleton to functions * Revert "Put rootDirs into subprojects" This partially reverts commite1d4292ce3
. It seems like this might not be necessary after all. However some other change made on this branch seems to have fixed the .svelte.d.ts imports * Introduce i18n-bundles to remove circular import There was a circular import i18n.ts <-> i18n-translate.ts * Create own directory for i18n * Move lib/i18n/translate to lib/translate * This restores tree shaking * Update tsconfig libs and module * es2018-2020 have wide support on all modern browsers including * Switch bundles and langs inside i18n to variables again * Add missing copyright header * Rename translate.ts to ftl.ts * Remove the symlinks again I added them to fix to have completion for tr, however this would have also have meant to abandon the tree shaking. As we want to have tree shaking, it's also not necessary to have the symlinks anymore * Revert "Update tsconfig libs and module" This reverts commit0a96776a47
. * move withCollapsedWhitespace back to i18n/utils * Add back /ts as in rootDirs
This commit is contained in:
parent
26e2941950
commit
dec0fbe845
66 changed files with 265 additions and 233 deletions
|
@ -1,4 +1,5 @@
|
||||||
licenses.json
|
licenses.json
|
||||||
vendor
|
vendor
|
||||||
*.svelte.d.ts
|
lib/translate.ts
|
||||||
|
lib/i18n/modules.ts
|
||||||
backend_proto.d.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
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -3,8 +3,8 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
import MapperRow from "./MapperRow.svelte";
|
import MapperRow from "./MapperRow.svelte";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import { ChangeNotetypeState, MapContext } from "./lib";
|
import { ChangeNotetypeState, MapContext } from "./lib";
|
||||||
import { slide } from "svelte/transition";
|
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
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
import type { ChangeNotetypeState } from "./lib";
|
import type { ChangeNotetypeState } from "./lib";
|
||||||
import { withButton } from "../components/helpers";
|
import { withButton } from "../components/helpers";
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ 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 * as tr from "../lib/ftl";
|
||||||
|
|
||||||
export let info: Scheduler.CongratsInfoResponse;
|
export let info: Scheduler.CongratsInfoResponse;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
const congrats = tr.schedulingCongratulationsFinished();
|
const congrats = tr.schedulingCongratulationsFinished();
|
||||||
let nextLearnMsg: string;
|
let nextLearnMsg: string;
|
||||||
|
|
|
@ -4,8 +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 * as tr from "../lib/ftl";
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
export async function getCongratsInfo(): Promise<Scheduler.CongratsInfoResponse> {
|
export async function getCongratsInfo(): Promise<Scheduler.CongratsInfoResponse> {
|
||||||
return Scheduler.CongratsInfoResponse.decode(
|
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
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -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 * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -3,10 +3,10 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
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 * as tr from "../lib/ftl";
|
||||||
import type { DeckOptionsState } from "./lib";
|
import type { DeckOptionsState } from "./lib";
|
||||||
|
|
||||||
export let state: DeckOptionsState;
|
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
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -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 * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -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 * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -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 * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -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 * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -3,14 +3,15 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
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";
|
||||||
import SpinBoxRow from "./SpinBoxRow.svelte";
|
import SpinBoxRow from "./SpinBoxRow.svelte";
|
||||||
import EnumSelectorRow from "./EnumSelectorRow.svelte";
|
import EnumSelectorRow from "./EnumSelectorRow.svelte";
|
||||||
import Warning from "./Warning.svelte";
|
import Warning from "./Warning.svelte";
|
||||||
|
|
||||||
import type { DeckOptionsState } from "./lib";
|
import type { DeckOptionsState } from "./lib";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
|
|
||||||
export let state: DeckOptionsState;
|
export let state: DeckOptionsState;
|
||||||
export let api = {};
|
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
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -3,11 +3,12 @@ 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 * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
import { withButton } from "../components/helpers";
|
import { withButton } from "../components/helpers";
|
||||||
|
import { withCollapsedWhitespace } from "../lib/i18n";
|
||||||
|
|
||||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||||
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
||||||
|
@ -41,7 +42,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
? tr.deckConfigWillRequireFullSync() + " "
|
? tr.deckConfigWillRequireFullSync() + " "
|
||||||
: "") +
|
: "") +
|
||||||
tr.deckConfigConfirmRemoveName({ name: state.getCurrentName() });
|
tr.deckConfigConfirmRemoveName({ name: state.getCurrentName() });
|
||||||
if (confirm(tr.i18n.withCollapsedWhitespace(msg))) {
|
if (confirm(withCollapsedWhitespace(msg))) {
|
||||||
try {
|
try {
|
||||||
state.removeCurrentConfig();
|
state.removeCurrentConfig();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -3,11 +3,11 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
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";
|
||||||
import SwitchRow from "./SwitchRow.svelte";
|
import SwitchRow from "./SwitchRow.svelte";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import type { DeckOptionsState } from "./lib";
|
import type { DeckOptionsState } from "./lib";
|
||||||
|
|
||||||
export let state: DeckOptionsState;
|
export let state: DeckOptionsState;
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { DeckConfig } from "../lib/proto";
|
||||||
import { postRequest } from "../lib/postrequest";
|
import { postRequest } from "../lib/postrequest";
|
||||||
import { Writable, writable, get, Readable, readable } from "svelte/store";
|
import { Writable, writable, get, Readable, readable } from "svelte/store";
|
||||||
import { isEqual, cloneDeep } from "lodash-es";
|
import { isEqual, cloneDeep } from "lodash-es";
|
||||||
import * as tr from "../lib/i18n";
|
import { localeCompare } from "../lib/i18n";
|
||||||
import type { DynamicSvelteComponent } from "../sveltelib/dynamicComponent";
|
import type { DynamicSvelteComponent } from "../sveltelib/dynamicComponent";
|
||||||
|
|
||||||
export async function getDeckOptionsInfo(
|
export async function getDeckOptionsInfo(
|
||||||
|
@ -278,9 +278,7 @@ export class DeckOptionsState {
|
||||||
useCount,
|
useCount,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
list.sort((a, b) =>
|
list.sort((a, b) => localeCompare(a.name, b.name, { sensitivity: "base" }));
|
||||||
a.name.localeCompare(b.name, tr.i18n.langs, { sensitivity: "base" })
|
|
||||||
);
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
|
|
||||||
export const reviewMixChoices = (): string[] => [
|
export const reviewMixChoices = (): string[] => [
|
||||||
tr.deckConfigReviewMixMixWithReviews(),
|
tr.deckConfigReviewMixMixWithReviews(),
|
||||||
|
|
|
@ -3,12 +3,11 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
import IconButton from "../components/IconButton.svelte";
|
import IconButton from "../components/IconButton.svelte";
|
||||||
import WithShortcut from "../components/WithShortcut.svelte";
|
import WithShortcut from "../components/WithShortcut.svelte";
|
||||||
import OnlyEditable from "./OnlyEditable.svelte";
|
import OnlyEditable from "./OnlyEditable.svelte";
|
||||||
|
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import { withButton } from "../components/helpers";
|
import { withButton } from "../components/helpers";
|
||||||
import { ellipseIcon } from "./icons";
|
import { ellipseIcon } from "./icons";
|
||||||
import { forEditorField } from ".";
|
import { forEditorField } from ".";
|
||||||
|
|
|
@ -3,8 +3,6 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||||
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
||||||
import IconButton from "../components/IconButton.svelte";
|
import IconButton from "../components/IconButton.svelte";
|
||||||
|
@ -13,6 +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 * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
|
@ -3,8 +3,6 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||||
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
||||||
import IconButton from "../components/IconButton.svelte";
|
import IconButton from "../components/IconButton.svelte";
|
||||||
|
@ -14,6 +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 * as tr from "../lib/ftl";
|
||||||
import { getListItem } from "../lib/dom";
|
import { getListItem } from "../lib/dom";
|
||||||
import { getCurrentField, execCommand } from "./helpers";
|
import { getCurrentField, execCommand } from "./helpers";
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -3,12 +3,11 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||||
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
||||||
import CommandIconButton from "./CommandIconButton.svelte";
|
import CommandIconButton from "./CommandIconButton.svelte";
|
||||||
|
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import {
|
import {
|
||||||
boldIcon,
|
boldIcon,
|
||||||
italicIcon,
|
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
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
|
|
||||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||||
import ButtonGroupItem from "../components/ButtonGroupItem.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
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
|
|
||||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||||
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
import ButtonGroupItem from "../components/ButtonGroupItem.svelte";
|
||||||
|
|
|
@ -3,12 +3,11 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
import ButtonGroup from "../components/ButtonGroup.svelte";
|
||||||
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 * as tr from "../lib/ftl";
|
||||||
import { inlineIcon, blockIcon } from "./icons";
|
import { inlineIcon, blockIcon } from "./icons";
|
||||||
|
|
||||||
export let activeImage: HTMLImageElement;
|
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">
|
<script lang="typescript">
|
||||||
import { bridgeCommand } from "../lib/bridgecommand";
|
import { bridgeCommand } from "../lib/bridgecommand";
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
import { withButton } from "../components/helpers";
|
import { withButton } from "../components/helpers";
|
||||||
|
|
||||||
import ButtonGroup from "../components/ButtonGroup.svelte";
|
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">
|
<script lang="typescript">
|
||||||
import { bridgeCommand } from "../lib/bridgecommand";
|
import { bridgeCommand } from "../lib/bridgecommand";
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
import { withButton } from "../components/helpers";
|
import { withButton } from "../components/helpers";
|
||||||
|
|
||||||
import WithShortcut from "../components/WithShortcut.svelte";
|
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
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
import { bridgeCommand } from "../lib/bridgecommand";
|
import { bridgeCommand } from "../lib/bridgecommand";
|
||||||
import { fieldFocusedKey, inCodableKey } from "./context-keys";
|
import { fieldFocusedKey, inCodableKey } from "./context-keys";
|
||||||
|
|
||||||
|
|
|
@ -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 type { EditorField } from "./editor-field";
|
import type { EditorField } from "./editor-field";
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
|
|
||||||
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";
|
||||||
|
|
|
@ -13,6 +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 * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
@ -20,7 +21,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import type { GraphData } from "./added";
|
import type { GraphData } from "./added";
|
||||||
|
|
||||||
export let sourceData: Stats.GraphsResponse | null = null;
|
export let sourceData: Stats.GraphsResponse | null = null;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
||||||
|
|
||||||
let histogramData = null as HistogramData | null;
|
let histogramData = null as HistogramData | null;
|
||||||
|
|
|
@ -4,6 +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 * as tr from "../lib/ftl";
|
||||||
|
|
||||||
import Graph from "./Graph.svelte";
|
import Graph from "./Graph.svelte";
|
||||||
import InputBox from "./InputBox.svelte";
|
import InputBox from "./InputBox.svelte";
|
||||||
|
@ -15,7 +16,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { defaultGraphBounds, GraphRange, RevlogRange } from "./graph-helpers";
|
import { defaultGraphBounds, GraphRange, RevlogRange } from "./graph-helpers";
|
||||||
|
|
||||||
export let sourceData: Stats.GraphsResponse | null = null;
|
export let sourceData: Stats.GraphsResponse | null = null;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
export let revlogRange: RevlogRange;
|
export let revlogRange: RevlogRange;
|
||||||
|
|
||||||
let graphRange: GraphRange = GraphRange.Year;
|
let graphRange: GraphRange = GraphRange.Year;
|
||||||
|
|
|
@ -3,10 +3,10 @@ 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 { 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 * as tr from "../lib/ftl";
|
||||||
import { createEventDispatcher } from "svelte";
|
|
||||||
|
|
||||||
import Graph from "./Graph.svelte";
|
import Graph from "./Graph.svelte";
|
||||||
import InputBox from "./InputBox.svelte";
|
import InputBox from "./InputBox.svelte";
|
||||||
|
@ -21,7 +21,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let sourceData: Stats.GraphsResponse;
|
export let sourceData: Stats.GraphsResponse;
|
||||||
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
||||||
export let revlogRange: RevlogRange;
|
export let revlogRange: RevlogRange;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
export let nightMode: boolean;
|
export let nightMode: boolean;
|
||||||
|
|
||||||
let { calendarFirstDayOfWeek } = preferences;
|
let { calendarFirstDayOfWeek } = preferences;
|
||||||
|
|
|
@ -3,20 +3,19 @@ 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 { createEventDispatcher } from "svelte";
|
|
||||||
import type { Stats } from "../lib/proto";
|
|
||||||
import type { PreferenceStore } from "../sveltelib/preferences";
|
|
||||||
|
|
||||||
import Graph from "./Graph.svelte";
|
import Graph from "./Graph.svelte";
|
||||||
import InputBox from "./InputBox.svelte";
|
import InputBox from "./InputBox.svelte";
|
||||||
|
|
||||||
|
import { createEventDispatcher } from "svelte";
|
||||||
|
import type { Stats } from "../lib/proto";
|
||||||
|
import type { PreferenceStore } from "../sveltelib/preferences";
|
||||||
|
import * as translate from "../lib/ftl";
|
||||||
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";
|
||||||
import type { GraphData, TableDatum } from "./card-counts";
|
import type { GraphData, TableDatum } from "./card-counts";
|
||||||
|
|
||||||
export let sourceData: Stats.GraphsResponse;
|
export let sourceData: Stats.GraphsResponse;
|
||||||
import * as tr2 from "../lib/i18n";
|
|
||||||
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
||||||
|
|
||||||
let { cardCountsSeparateInactive, browserLinksSupported } = preferences;
|
let { cardCountsSeparateInactive, browserLinksSupported } = preferences;
|
||||||
|
@ -36,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 = tr2.statisticsCountsSeparateSuspendedBuriedCards();
|
const label = translate.statisticsCountsSeparateSuspendedBuriedCards();
|
||||||
const total = tr2.statisticsCountsTotalCards();
|
const total = translate.statisticsCountsTotalCards();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Graph title={graphData.title}>
|
<Graph title={graphData.title}>
|
||||||
|
|
|
@ -4,10 +4,10 @@ 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 * as tr from "../lib/i18n";
|
|
||||||
import type { PreferenceStore } from "../sveltelib/preferences";
|
import type { PreferenceStore } from "../sveltelib/preferences";
|
||||||
|
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
|
|
||||||
import HistogramGraph from "./HistogramGraph.svelte";
|
import HistogramGraph from "./HistogramGraph.svelte";
|
||||||
import Graph from "./Graph.svelte";
|
import Graph from "./Graph.svelte";
|
||||||
|
|
|
@ -14,6 +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 * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
@ -21,7 +22,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import type { GraphData } from "./future-due";
|
import type { GraphData } from "./future-due";
|
||||||
|
|
||||||
export let sourceData: Stats.GraphsResponse | null = null;
|
export let sourceData: Stats.GraphsResponse | null = null;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<SearchEventMap>();
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
||||||
|
|
|
@ -3,10 +3,10 @@ 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 * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
export let revlogRange: RevlogRange;
|
export let revlogRange: RevlogRange;
|
||||||
export let graphRange: GraphRange;
|
export let graphRange: GraphRange;
|
||||||
export let followRevlog: boolean = false;
|
export let followRevlog: boolean = false;
|
||||||
|
|
|
@ -3,8 +3,6 @@ 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 type { Stats } from "../lib/proto";
|
|
||||||
|
|
||||||
import Graph from "./Graph.svelte";
|
import Graph from "./Graph.svelte";
|
||||||
import InputBox from "./InputBox.svelte";
|
import InputBox from "./InputBox.svelte";
|
||||||
import AxisTicks from "./AxisTicks.svelte";
|
import AxisTicks from "./AxisTicks.svelte";
|
||||||
|
@ -12,11 +10,13 @@ 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 CumulativeOverlay from "./CumulativeOverlay.svelte";
|
import CumulativeOverlay from "./CumulativeOverlay.svelte";
|
||||||
import HoverColumns from "./HoverColumns.svelte";
|
import HoverColumns from "./HoverColumns.svelte";
|
||||||
|
|
||||||
|
import type { Stats } from "../lib/proto";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import { defaultGraphBounds, RevlogRange, GraphRange } from "./graph-helpers";
|
import { defaultGraphBounds, RevlogRange, GraphRange } from "./graph-helpers";
|
||||||
import { renderHours } from "./hours";
|
import { renderHours } from "./hours";
|
||||||
|
|
||||||
export let sourceData: Stats.GraphsResponse | null = null;
|
export let sourceData: Stats.GraphsResponse | null = null;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
export let revlogRange: RevlogRange;
|
export let revlogRange: RevlogRange;
|
||||||
let graphRange: GraphRange = GraphRange.Year;
|
let graphRange: GraphRange = GraphRange.Year;
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,16 @@ 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 { timeSpan, MONTH } from "../lib/time";
|
|
||||||
|
|
||||||
import type { Stats } from "../lib/proto";
|
|
||||||
import type { PreferenceStore } from "../sveltelib/preferences";
|
|
||||||
import { createEventDispatcher } from "svelte";
|
|
||||||
|
|
||||||
import Graph from "./Graph.svelte";
|
import Graph from "./Graph.svelte";
|
||||||
import InputBox from "./InputBox.svelte";
|
import InputBox from "./InputBox.svelte";
|
||||||
import HistogramGraph from "./HistogramGraph.svelte";
|
import HistogramGraph from "./HistogramGraph.svelte";
|
||||||
import TableData from "./TableData.svelte";
|
import TableData from "./TableData.svelte";
|
||||||
|
|
||||||
|
import { timeSpan, MONTH } from "../lib/time";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
|
import type { Stats } from "../lib/proto";
|
||||||
|
import type { PreferenceStore } from "../sveltelib/preferences";
|
||||||
|
import { createEventDispatcher } from "svelte";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import {
|
import {
|
||||||
gatherIntervalData,
|
gatherIntervalData,
|
||||||
|
@ -24,7 +23,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
import type { TableDatum, SearchEventMap } from "./graph-helpers";
|
||||||
|
|
||||||
export let sourceData: Stats.GraphsResponse | null = null;
|
export let sourceData: Stats.GraphsResponse | null = null;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
export let preferences: PreferenceStore<Stats.GraphPreferences>;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<SearchEventMap>();
|
const dispatch = createEventDispatcher<SearchEventMap>();
|
||||||
|
|
|
@ -4,8 +4,10 @@ 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 * as tr from "../lib/ftl";
|
||||||
|
|
||||||
export let bounds: GraphBounds;
|
export let bounds: GraphBounds;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
const noData = tr.statisticsNoData();
|
const noData = tr.statisticsNoData();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,10 @@ 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 type { Writable } from "svelte/store";
|
|
||||||
|
|
||||||
import InputBox from "./InputBox.svelte";
|
import InputBox from "./InputBox.svelte";
|
||||||
|
|
||||||
import * as tr from "../lib/i18n";
|
import type { Writable } from "svelte/store";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import { RevlogRange, daysToRevlogRange } from "./graph-helpers";
|
import { RevlogRange, daysToRevlogRange } from "./graph-helpers";
|
||||||
|
|
||||||
enum SearchRange {
|
enum SearchRange {
|
||||||
|
|
|
@ -3,8 +3,6 @@ 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 type { Stats } from "../lib/proto";
|
|
||||||
|
|
||||||
import Graph from "./Graph.svelte";
|
import Graph from "./Graph.svelte";
|
||||||
import InputBox from "./InputBox.svelte";
|
import InputBox from "./InputBox.svelte";
|
||||||
import NoDataOverlay from "./NoDataOverlay.svelte";
|
import NoDataOverlay from "./NoDataOverlay.svelte";
|
||||||
|
@ -14,6 +12,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import AxisTicks from "./AxisTicks.svelte";
|
import AxisTicks from "./AxisTicks.svelte";
|
||||||
import HoverColumns from "./HoverColumns.svelte";
|
import HoverColumns from "./HoverColumns.svelte";
|
||||||
|
|
||||||
|
import type { Stats } from "../lib/proto";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
@ -21,7 +21,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
export let sourceData: Stats.GraphsResponse | null = null;
|
export let sourceData: Stats.GraphsResponse | null = null;
|
||||||
export let revlogRange: RevlogRange;
|
export let revlogRange: RevlogRange;
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
let graphData: GraphData | null = null;
|
let graphData: GraphData | null = null;
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import type { TableDatum } from "./graph-helpers";
|
import type { TableDatum } from "./graph-helpers";
|
||||||
import { i18n } from "../lib/i18n";
|
import { direction } from "../lib/i18n";
|
||||||
export let tableData: TableDatum[];
|
export let tableData: TableDatum[];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<table dir={i18n.direction()}>
|
<table dir={direction()}>
|
||||||
{#each tableData as { label, value }}
|
{#each tableData as { label, value }}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="align-end">{label}:</td>
|
<td class="align-end">{label}:</td>
|
||||||
|
|
|
@ -19,10 +19,10 @@ import {
|
||||||
import type { Bin } from "d3";
|
import type { Bin } from "d3";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
|
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
daysAdded: number[];
|
daysAdded: number[];
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
@typescript-eslint/no-explicit-any: "off",
|
@typescript-eslint/no-explicit-any: "off",
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Stats } from "../lib/proto";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
interpolateRdYlGn,
|
interpolateRdYlGn,
|
||||||
select,
|
select,
|
||||||
|
@ -19,6 +17,8 @@ import {
|
||||||
axisLeft,
|
axisLeft,
|
||||||
sum,
|
sum,
|
||||||
} from "d3";
|
} from "d3";
|
||||||
|
import { Stats } from "../lib/proto";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import {
|
import {
|
||||||
GraphBounds,
|
GraphBounds,
|
||||||
|
@ -26,7 +26,6 @@ import {
|
||||||
GraphRange,
|
GraphRange,
|
||||||
millisecondCutoffForRange,
|
millisecondCutoffForRange,
|
||||||
} from "./graph-helpers";
|
} from "./graph-helpers";
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
type ButtonCounts = [number, number, number, number];
|
type ButtonCounts = [number, number, number, number];
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ import {
|
||||||
SearchDispatch,
|
SearchDispatch,
|
||||||
} from "./graph-helpers";
|
} from "./graph-helpers";
|
||||||
import { clickableClass } from "./graph-styles";
|
import { clickableClass } from "./graph-styles";
|
||||||
import { i18n } from "../lib/i18n";
|
import { weekdayLabel, toLocaleString } from "../lib/i18n";
|
||||||
import * as tr from "../lib/i18n";
|
import * as tr from "../lib/ftl";
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
// indexed by day, where day is relative to today
|
// indexed by day, where day is relative to today
|
||||||
|
@ -155,7 +155,7 @@ export function renderCalendar(
|
||||||
.interpolator((n) => interpolateBlues(cappedRange(n)!));
|
.interpolator((n) => interpolateBlues(cappedRange(n)!));
|
||||||
|
|
||||||
function tooltipText(d: DayDatum): string {
|
function tooltipText(d: DayDatum): string {
|
||||||
const date = d.date.toLocaleString(i18n.langs, {
|
const date = toLocaleString(d.date, {
|
||||||
weekday: "long",
|
weekday: "long",
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "long",
|
month: "long",
|
||||||
|
@ -172,7 +172,7 @@ export function renderCalendar(
|
||||||
.selectAll("text")
|
.selectAll("text")
|
||||||
.data(sourceData.weekdayLabels)
|
.data(sourceData.weekdayLabels)
|
||||||
.join("text")
|
.join("text")
|
||||||
.text((d: number) => i18n.weekdayLabel(d))
|
.text((d: number) => weekdayLabel(d))
|
||||||
.attr("width", x(-1)! - 2)
|
.attr("width", x(-1)! - 2)
|
||||||
.attr("height", height - 2)
|
.attr("height", height - 2)
|
||||||
.attr("x", x(1)! - 3)
|
.attr("x", x(1)! - 3)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
@typescript-eslint/no-explicit-any: "off",
|
@typescript-eslint/no-explicit-any: "off",
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
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 {
|
||||||
|
@ -22,8 +23,6 @@ import {
|
||||||
} from "d3";
|
} from "d3";
|
||||||
import type { GraphBounds } from "./graph-helpers";
|
import type { GraphBounds } from "./graph-helpers";
|
||||||
|
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
type Count = [string, number, boolean, string];
|
type Count = [string, number, boolean, string];
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
|
@ -16,11 +16,10 @@ import {
|
||||||
interpolateRdYlGn,
|
interpolateRdYlGn,
|
||||||
} from "d3";
|
} from "d3";
|
||||||
import type { Bin, ScaleLinear } from "d3";
|
import type { Bin, ScaleLinear } from "d3";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
eases: number[];
|
eases: number[];
|
||||||
|
|
|
@ -17,13 +17,13 @@ import {
|
||||||
interpolateGreens,
|
interpolateGreens,
|
||||||
} from "d3";
|
} from "d3";
|
||||||
import type { Bin } from "d3";
|
import type { Bin } from "d3";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
|
|
||||||
import { GraphRange } from "./graph-helpers";
|
import { GraphRange } from "./graph-helpers";
|
||||||
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
export interface GraphData {
|
export interface GraphData {
|
||||||
dueCounts: Map<number, number>;
|
dueCounts: Map<number, number>;
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
curveBasis,
|
curveBasis,
|
||||||
} from "d3";
|
} from "d3";
|
||||||
|
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import { showTooltip, hideTooltip } from "./tooltip";
|
import { showTooltip, hideTooltip } from "./tooltip";
|
||||||
import {
|
import {
|
||||||
GraphBounds,
|
GraphBounds,
|
||||||
|
@ -29,7 +30,6 @@ import {
|
||||||
millisecondCutoffForRange,
|
millisecondCutoffForRange,
|
||||||
} from "./graph-helpers";
|
} from "./graph-helpers";
|
||||||
import { oddTickClass } from "./graph-styles";
|
import { oddTickClass } from "./graph-styles";
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
interface Hour {
|
interface Hour {
|
||||||
hour: number;
|
hour: number;
|
||||||
|
|
|
@ -18,12 +18,12 @@ import {
|
||||||
interpolateBlues,
|
interpolateBlues,
|
||||||
} from "d3";
|
} from "d3";
|
||||||
import type { Bin } from "d3";
|
import type { Bin } from "d3";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
|
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";
|
||||||
|
|
||||||
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
import type { TableDatum, SearchDispatch } from "./graph-helpers";
|
||||||
import { timeSpan } from "../lib/time";
|
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
export interface IntervalGraphData {
|
export interface IntervalGraphData {
|
||||||
intervals: number[];
|
intervals: number[];
|
||||||
|
|
|
@ -32,10 +32,10 @@ import {
|
||||||
} from "d3";
|
} from "d3";
|
||||||
import type { Bin } from "d3";
|
import type { Bin } from "d3";
|
||||||
|
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
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";
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
interface Reviews {
|
interface Reviews {
|
||||||
learn: number;
|
learn: number;
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
|
|
||||||
import { Stats } from "../lib/proto";
|
import { Stats } from "../lib/proto";
|
||||||
import { studiedToday } from "../lib/time";
|
import { studiedToday } from "../lib/time";
|
||||||
|
import * as tr from "../lib/ftl";
|
||||||
import * as tr from "../lib/i18n";
|
|
||||||
|
|
||||||
export interface TodayData {
|
export interface TodayData {
|
||||||
title: string;
|
title: string;
|
||||||
|
|
|
@ -1,17 +1,11 @@
|
||||||
|
load("@rules_python//python:defs.bzl", "py_binary")
|
||||||
load("//ts:prettier.bzl", "prettier_test")
|
load("//ts:prettier.bzl", "prettier_test")
|
||||||
load("//ts:eslint.bzl", "eslint_test")
|
load("//ts:eslint.bzl", "eslint_test")
|
||||||
load("//ts:protobuf.bzl", "protobufjs_library")
|
load("//ts:protobuf.bzl", "protobufjs_library")
|
||||||
load("//ts:typescript.bzl", "typescript")
|
load("//ts:typescript.bzl", "typescript")
|
||||||
load("@rules_python//python:defs.bzl", "py_binary")
|
|
||||||
load("@py_deps//:requirements.bzl", "requirement")
|
load("@py_deps//:requirements.bzl", "requirement")
|
||||||
load("//ts:jest.bzl", "jest_test")
|
load("//ts:jest.bzl", "jest_test")
|
||||||
|
|
||||||
protobufjs_library(
|
|
||||||
name = "backend_proto",
|
|
||||||
proto = "//proto:backend_proto_lib",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
py_binary(
|
py_binary(
|
||||||
name = "genfluent",
|
name = "genfluent",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
@ -22,21 +16,33 @@ py_binary(
|
||||||
requirement("stringcase"),
|
requirement("stringcase"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
_i18n_generated = [
|
||||||
|
"ftl.ts",
|
||||||
|
"i18n/modules.ts",
|
||||||
|
]
|
||||||
|
|
||||||
genrule(
|
genrule(
|
||||||
name = "fluent_gen",
|
name = "fluent_gen",
|
||||||
outs = ["i18n.ts"],
|
outs = _i18n_generated,
|
||||||
cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $@",
|
cmd = "$(location genfluent) $(location //rslib/i18n:strings.json) $(OUTS)",
|
||||||
tools = [
|
tools = [
|
||||||
"genfluent",
|
"genfluent",
|
||||||
"//rslib/i18n:strings.json",
|
"//rslib/i18n:strings.json",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
protobufjs_library(
|
||||||
|
name = "backend_proto",
|
||||||
|
proto = "//proto:backend_proto_lib",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
typescript(
|
typescript(
|
||||||
name = "lib",
|
name = "lib",
|
||||||
generated = [
|
generated = [
|
||||||
":i18n.ts",
|
":backend_proto.d.ts",
|
||||||
|
":ftl.ts",
|
||||||
|
":i18n/modules.ts",
|
||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
":backend_proto",
|
":backend_proto",
|
||||||
|
|
|
@ -7,7 +7,7 @@ from typing import List, Literal, TypedDict
|
||||||
|
|
||||||
import stringcase
|
import stringcase
|
||||||
|
|
||||||
strings_json, outfile = sys.argv[1:]
|
strings_json, translate_out, modules_out = sys.argv[1:]
|
||||||
modules = json.load(open(strings_json, encoding="utf8"))
|
modules = json.load(open(strings_json, encoding="utf8"))
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,10 +17,12 @@ class Variable(TypedDict):
|
||||||
|
|
||||||
|
|
||||||
def methods() -> str:
|
def methods() -> str:
|
||||||
out = [
|
out = [ """import type { FluentVariable } from "@fluent/bundle";
|
||||||
'import { i18n } from "./i18n_helpers";',
|
import { getMessage } from "./i18n";
|
||||||
'export { i18n, setupI18n } from "./i18n_helpers";',
|
|
||||||
]
|
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("-", "_"))
|
||||||
|
@ -31,7 +33,7 @@ def methods() -> str:
|
||||||
f"""
|
f"""
|
||||||
/** {doc} */
|
/** {doc} */
|
||||||
export function {key}({arg_types}): string {{
|
export function {key}({arg_types}): string {{
|
||||||
return i18n.translate("{translation["key"]}"{args})
|
return translate("{translation["key"]}"{args})
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
@ -102,17 +104,17 @@ def module_names() -> str:
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
|
||||||
out = ""
|
def write(outfile, out) -> None:
|
||||||
|
open(outfile, "wb").write(
|
||||||
out += methods()
|
(
|
||||||
out += module_names()
|
f"""// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
|
||||||
open(outfile, "wb").write(
|
|
||||||
(
|
|
||||||
"""// 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
|
||||||
|
|
||||||
"""
|
"""
|
||||||
+ out
|
+ out
|
||||||
).encode("utf8")
|
).encode("utf8")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
write(translate_out, str(methods()))
|
||||||
|
write(modules_out, str(module_names()))
|
||||||
|
|
46
ts/lib/i18n/bundles.ts
Normal file
46
ts/lib/i18n/bundles.ts
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
import { FluentNumber } from "@fluent/bundle";
|
||||||
|
import type { FluentBundle, FluentVariable } from "@fluent/bundle";
|
||||||
|
|
||||||
|
let bundles: FluentBundle[] = [];
|
||||||
|
|
||||||
|
export function setBundles(newBundles: FluentBundle[]): void {
|
||||||
|
bundles = newBundles;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function firstLanguage(): string {
|
||||||
|
return bundles[0].locales[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
function toFluentNumber(num: number): FluentNumber {
|
||||||
|
return new FluentNumber(num, {
|
||||||
|
maximumFractionDigits: 2,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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, formatArgs(args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
6
ts/lib/i18n/index.ts
Normal file
6
ts/lib/i18n/index.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
export * from "./bundles";
|
||||||
|
export * from "./modules";
|
||||||
|
export * from "./utils";
|
87
ts/lib/i18n/utils.ts
Normal file
87
ts/lib/i18n/utils.ts
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
import "intl-pluralrules";
|
||||||
|
import { FluentBundle, FluentResource } from "@fluent/bundle";
|
||||||
|
|
||||||
|
import { firstLanguage, setBundles } from "./bundles";
|
||||||
|
import type { ModuleName } from "./modules";
|
||||||
|
|
||||||
|
export function supportsVerticalText(): boolean {
|
||||||
|
const firstLang = firstLanguage();
|
||||||
|
return (
|
||||||
|
firstLang.startsWith("ja") ||
|
||||||
|
firstLang.startsWith("zh") ||
|
||||||
|
firstLang.startsWith("ko")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function direction(): string {
|
||||||
|
const firstLang = firstLanguage();
|
||||||
|
if (
|
||||||
|
firstLang.startsWith("ar") ||
|
||||||
|
firstLang.startsWith("he") ||
|
||||||
|
firstLang.startsWith("fa")
|
||||||
|
) {
|
||||||
|
return "rtl";
|
||||||
|
} else {
|
||||||
|
return "ltr";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function weekdayLabel(n: number): string {
|
||||||
|
const firstLang = firstLanguage();
|
||||||
|
const now = new Date();
|
||||||
|
const daysFromToday = -now.getDay() + n;
|
||||||
|
const desiredDay = new Date(now.getTime() + daysFromToday * 86_400_000);
|
||||||
|
return desiredDay.toLocaleDateString(firstLang, {
|
||||||
|
weekday: "narrow",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let langs: string[] = [];
|
||||||
|
|
||||||
|
export function toLocaleString(
|
||||||
|
date: Date,
|
||||||
|
options?: Intl.DateTimeFormatOptions
|
||||||
|
): string {
|
||||||
|
return date.toLocaleDateString(langs, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function localeCompare(
|
||||||
|
first: string,
|
||||||
|
second: string,
|
||||||
|
options?: Intl.CollatorOptions
|
||||||
|
): number {
|
||||||
|
return first.localeCompare(second, langs, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Treat text like HTML, merging multiple spaces and converting
|
||||||
|
/// newlines to spaces.
|
||||||
|
export function withCollapsedWhitespace(s: string): string {
|
||||||
|
return s.replace(/\s+/g, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setupI18n(args: { modules: ModuleName[] }): Promise<void> {
|
||||||
|
const resp = await fetch("/_anki/i18nResources", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(args),
|
||||||
|
});
|
||||||
|
if (!resp.ok) {
|
||||||
|
throw Error(`unexpected reply: ${resp.statusText}`);
|
||||||
|
}
|
||||||
|
const json = await resp.json();
|
||||||
|
|
||||||
|
const newBundles: FluentBundle[] = [];
|
||||||
|
for (const i in json.resources) {
|
||||||
|
const text = json.resources[i];
|
||||||
|
const lang = json.langs[i];
|
||||||
|
const bundle = new FluentBundle([lang, "en-US"]);
|
||||||
|
const resource = new FluentResource(text);
|
||||||
|
bundle.addResource(resource);
|
||||||
|
newBundles.push(bundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
setBundles(newBundles);
|
||||||
|
langs = json.langs;
|
||||||
|
}
|
|
@ -1,104 +0,0 @@
|
||||||
// Copyright: Ankitects Pty Ltd and contributors
|
|
||||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
||||||
|
|
||||||
// An i18n singleton and setupI18n is re-exported via the generated i18n.ts file,
|
|
||||||
// so you should not need to access this file directly.
|
|
||||||
|
|
||||||
import "intl-pluralrules";
|
|
||||||
import { FluentBundle, FluentResource, FluentNumber } from "@fluent/bundle";
|
|
||||||
|
|
||||||
type RecordVal = number | string | FluentNumber;
|
|
||||||
|
|
||||||
function formatNumbers(args?: Record<string, RecordVal>): void {
|
|
||||||
if (!args) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const key of Object.keys(args)) {
|
|
||||||
if (typeof args[key] === "number") {
|
|
||||||
args[key] = new FluentNumber(args[key] as number, {
|
|
||||||
maximumFractionDigits: 2,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class I18n {
|
|
||||||
bundles: FluentBundle[] = [];
|
|
||||||
langs: string[] = [];
|
|
||||||
|
|
||||||
translate(key: string, args?: Record<string, RecordVal>): string {
|
|
||||||
formatNumbers(args);
|
|
||||||
for (const bundle of this.bundles) {
|
|
||||||
const msg = bundle.getMessage(key);
|
|
||||||
if (msg && msg.value) {
|
|
||||||
return bundle.formatPattern(msg.value, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return `missing key: ${key}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
supportsVerticalText(): boolean {
|
|
||||||
const firstLang = this.bundles[0].locales[0];
|
|
||||||
return (
|
|
||||||
firstLang.startsWith("ja") ||
|
|
||||||
firstLang.startsWith("zh") ||
|
|
||||||
firstLang.startsWith("ko")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
direction(): string {
|
|
||||||
const firstLang = this.bundles[0].locales[0];
|
|
||||||
if (
|
|
||||||
firstLang.startsWith("ar") ||
|
|
||||||
firstLang.startsWith("he") ||
|
|
||||||
firstLang.startsWith("fa")
|
|
||||||
) {
|
|
||||||
return "rtl";
|
|
||||||
} else {
|
|
||||||
return "ltr";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
weekdayLabel(n: number): string {
|
|
||||||
const firstLang = this.bundles[0].locales[0];
|
|
||||||
const now = new Date();
|
|
||||||
const daysFromToday = -now.getDay() + n;
|
|
||||||
const desiredDay = new Date(now.getTime() + daysFromToday * 86_400_000);
|
|
||||||
return desiredDay.toLocaleDateString(firstLang, {
|
|
||||||
weekday: "narrow",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Treat text like HTML, merging multiple spaces and converting
|
|
||||||
/// newlines to spaces.
|
|
||||||
withCollapsedWhitespace(s: string): string {
|
|
||||||
return s.replace(/\s+/g, " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// global singleton
|
|
||||||
export const i18n = new I18n();
|
|
||||||
|
|
||||||
import type { ModuleName } from "./i18n";
|
|
||||||
|
|
||||||
export async function setupI18n(args: { modules: ModuleName[] }): Promise<void> {
|
|
||||||
const resp = await fetch("/_anki/i18nResources", {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(args),
|
|
||||||
});
|
|
||||||
if (!resp.ok) {
|
|
||||||
throw Error(`unexpected reply: ${resp.statusText}`);
|
|
||||||
}
|
|
||||||
const json = await resp.json();
|
|
||||||
|
|
||||||
i18n.bundles = [];
|
|
||||||
for (const i in json.resources) {
|
|
||||||
const text = json.resources[i];
|
|
||||||
const lang = json.langs[i];
|
|
||||||
const bundle = new FluentBundle([lang, "en-US"]);
|
|
||||||
const resource = new FluentResource(text);
|
|
||||||
bundle.addResource(resource);
|
|
||||||
i18n.bundles.push(bundle);
|
|
||||||
}
|
|
||||||
i18n.langs = json.langs;
|
|
||||||
}
|
|
|
@ -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 * as tr from "./i18n";
|
import * as tr from "./ftl";
|
||||||
import { isApplePlatform } from "./platform";
|
import { isApplePlatform } from "./platform";
|
||||||
|
|
||||||
// those are the modifiers that Anki works with
|
// those are the modifiers that Anki works with
|
||||||
|
|
|
@ -2,6 +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 { anki } from "./backend_proto";
|
import { anki } from "./backend_proto";
|
||||||
|
|
||||||
import Cards = anki.cards;
|
import Cards = anki.cards;
|
||||||
import DeckConfig = anki.deckconfig;
|
import DeckConfig = anki.deckconfig;
|
||||||
import Notetypes = anki.notetypes;
|
import Notetypes = anki.notetypes;
|
||||||
|
|
|
@ -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 * as tr from "./i18n";
|
import * as tr from "./ftl";
|
||||||
|
|
||||||
export const SECOND = 1.0;
|
export const SECOND = 1.0;
|
||||||
export const MINUTE = 60.0 * SECOND;
|
export const MINUTE = 60.0 * SECOND;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"extends": "../tsconfig.json",
|
"extends": "../tsconfig.json",
|
||||||
"include": ["*", "../../bazel-bin/ts/lib/*"],
|
"include": ["*", "i18n/*"],
|
||||||
"references": [],
|
"references": [],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"types": ["jest"]
|
"types": ["jest"]
|
||||||
|
|
|
@ -17,14 +17,15 @@
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"composite": true,
|
"composite": true,
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"module": "es6",
|
"module": "es2020",
|
||||||
"lib": [
|
"lib": [
|
||||||
"es2017",
|
"es2017",
|
||||||
"es2018.intl",
|
"es2018.intl",
|
||||||
"es2019.array",
|
|
||||||
"es2018.promise",
|
"es2018.promise",
|
||||||
"es2020.promise",
|
"es2019.array",
|
||||||
|
"es2019.object",
|
||||||
"es2019.string",
|
"es2019.string",
|
||||||
|
"es2020.promise",
|
||||||
"dom",
|
"dom",
|
||||||
"dom.iterable"
|
"dom.iterable"
|
||||||
],
|
],
|
||||||
|
|
|
@ -4,12 +4,13 @@ load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "js_library")
|
||||||
def typescript(
|
def typescript(
|
||||||
name,
|
name,
|
||||||
srcs = None,
|
srcs = None,
|
||||||
|
exclude = [],
|
||||||
generated = [],
|
generated = [],
|
||||||
tsconfig = "tsconfig.json",
|
tsconfig = "tsconfig.json",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
**kwargs):
|
**kwargs):
|
||||||
if not srcs:
|
if not srcs:
|
||||||
srcs = native.glob(["**/*.ts"])
|
srcs = native.glob(["**/*.ts"], exclude = exclude)
|
||||||
|
|
||||||
# all tsconfig files must be in the bazel-out folder
|
# all tsconfig files must be in the bazel-out folder
|
||||||
copy_to_bin(
|
copy_to_bin(
|
||||||
|
|
Loading…
Reference in a new issue