From 1c1a691040427b6a0ab55e5c4606330eb5f3817d Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Fri, 26 Nov 2021 17:26:37 -0500 Subject: [PATCH] Add typing files for our translator libraries (#3175) --- .../js/src/common/translator-icu-rich.d.ts | 26 +++++++++++++++++++ .../core/js/src/common/translator-icu.d.ts | 17 ++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 framework/core/js/src/common/translator-icu-rich.d.ts create mode 100644 framework/core/js/src/common/translator-icu.d.ts diff --git a/framework/core/js/src/common/translator-icu-rich.d.ts b/framework/core/js/src/common/translator-icu-rich.d.ts new file mode 100644 index 000000000..08fb52765 --- /dev/null +++ b/framework/core/js/src/common/translator-icu-rich.d.ts @@ -0,0 +1,26 @@ +declare module '@askvortsov/rich-icu-message-formatter' { + type IValues = Record; + + type ITypeHandler = ( + value: string, + matches: string, + locale: string, + values: IValues, + format: (message: string, values: IValues) => string + ) => string; + type IRichHandler = (tag: any, values: IValues, contents: string) => any; + + type ValueOrArray = T | ValueOrArray[]; + type NestedStringArray = ValueOrArray; + + export class RichMessageFormatter { + locale: string | null; + constructor(locale: string | null, typeHandlers: Record, richHandler: IRichHandler); + + format(message: string, values: IValues): string; + process(message: string, values: IValues): NestedStringArray; + rich(message: string, values: IValues): NestedStringArray; + } + + export function mithrilRichHandler(tag: any, values: IValues, contents: string): any; +} diff --git a/framework/core/js/src/common/translator-icu.d.ts b/framework/core/js/src/common/translator-icu.d.ts new file mode 100644 index 000000000..d1ed498f5 --- /dev/null +++ b/framework/core/js/src/common/translator-icu.d.ts @@ -0,0 +1,17 @@ +declare module '@ultraq/icu-message-formatter' { + export function pluralTypeHandler( + value: string, + matches: string, + locale: string, + values: Record, + format: (text: string, values: Record) => string + ): string; + + export function selectTypeHandler( + value: string, + matches: string, + locale: string, + values: Record, + format: (text: string, values: Record) => string + ): string; +}