@manyducks.co/dolla 2.0.0-alpha.8 → 2.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import { createSettableState, createState, derive, toSettableState, toState, val
3
3
  import { type ViewFunction, type ViewNode } from "../view.js";
4
4
  import { type CrashViewProps } from "../views/default-crash-view.js";
5
5
  import { HTTP } from "./http.js";
6
- import { Language } from "./language.js";
6
+ import { I18n } from "./i18n.js";
7
7
  import { Render } from "./render.js";
8
8
  import { Router } from "./router.js";
9
9
  export type Environment = "development" | "production";
@@ -41,7 +41,7 @@ export type LoggerOptions = {
41
41
  export declare class Dolla {
42
42
  #private;
43
43
  readonly http: HTTP;
44
- readonly language: Language;
44
+ readonly i18n: I18n;
45
45
  readonly render: Render;
46
46
  readonly router: Router;
47
47
  constructor();
@@ -0,0 +1,59 @@
1
+ import { MaybeState, type State } from "../state.js";
2
+ import type { Stringable } from "../types.js";
3
+ import type { Dolla } from "./dolla.js";
4
+ /**
5
+ * An object where values are either a translated string or another nested Translation object.
6
+ */
7
+ type LocalizedStrings = Record<string, string | Record<string, string | Record<string, string | Record<string, string>>>>;
8
+ export interface TranslationConfig {
9
+ /**
10
+ * Name of the locale this translation is for (BCP 47 locale names recommended).
11
+ */
12
+ locale: string;
13
+ /**
14
+ * Path to a JSON file with translated strings for this language.
15
+ */
16
+ path?: string;
17
+ /**
18
+ * A callback function that returns a Promise that resolves to the translation object for this language.
19
+ */
20
+ fetch?: () => Promise<LocalizedStrings>;
21
+ }
22
+ export type I18nSetupOptions = {
23
+ /**
24
+ * Default locale to load on startup
25
+ */
26
+ locale?: string | null;
27
+ translations: TranslationConfig[];
28
+ };
29
+ /**
30
+ * Dolla's I(nternationalizatio)n module. Manages language translations and locale-based formatting.
31
+ */
32
+ export declare class I18n {
33
+ #private;
34
+ $locale: State<string | undefined>;
35
+ constructor(dolla: Dolla);
36
+ get locales(): string[];
37
+ setup(options: I18nSetupOptions): void;
38
+ setLocale(name: string): Promise<void>;
39
+ /**
40
+ * Returns a State containing the value at `key`.
41
+
42
+ * @param key - Key to the translated value.
43
+ * @param values - A map of {{placeholder}} names and the values to replace them with.
44
+ */
45
+ t(key: string, values?: Record<string, Stringable | State<Stringable>>): State<string>;
46
+ /**
47
+ * Format a number in the current locale.
48
+ */
49
+ formatNumber(count: number, options?: Intl.NumberFormatOptions): string;
50
+ /**
51
+ * Format a number in the current locale and get the result as a State that will update if the locale changes.
52
+ */
53
+ formatNumber$(count: MaybeState<number>, options?: Intl.NumberFormatOptions): State<string>;
54
+ formatDate(date: string | Date, options?: Intl.DateTimeFormatOptions): string;
55
+ formatDate$(date: MaybeState<string | Date>, options?: Intl.DateTimeFormatOptions): State<string>;
56
+ formatList(list: string[], options?: Intl.ListFormatOptions): string;
57
+ formatList$(list: MaybeState<string[]>, options?: Intl.ListFormatOptions): State<string>;
58
+ }
59
+ export {};
package/notes/scratch.md CHANGED
@@ -48,8 +48,8 @@ Doing this would make it possible to access things inside the Dolla app from _ou
48
48
  import Dolla from "@manyducks.co/dolla";
49
49
 
50
50
  // Languages: add translation, set language and get localized string as a signal
51
- Dolla.language.setup({
52
- initialLanguage: Dolla.language.detect({ fallback: "ja" }), // Detect user's language and fall back to passed value
51
+ Dolla.i18n.setup({
52
+ initialLanguage: Dolla.i18n.detect({ fallback: "ja" }), // Detect user's language and fall back to passed value
53
53
  languages: [
54
54
  { name: "ja", path: "/static/locales/ja.json" },
55
55
  {
@@ -63,8 +63,8 @@ Dolla.language.setup({
63
63
  ]
64
64
  });
65
65
 
66
- Dolla.language.$current
67
- Dolla.language.t$()
66
+ Dolla.i18n.$locale
67
+ Dolla.i18n.t$()
68
68
 
69
69
  // A single setup call to keep things contained (must happen before mount)
70
70
  Dolla.router.setup({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyducks.co/dolla",
3
- "version": "2.0.0-alpha.8",
3
+ "version": "2.0.0-alpha.9",
4
4
  "description": "Front-end components, routing and state management.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,41 +0,0 @@
1
- import { type State } from "../state.js";
2
- import type { Stringable } from "../types.js";
3
- import type { Dolla } from "./dolla.js";
4
- /**
5
- * An object where values are either a translated string or another nested Translation object.
6
- */
7
- type LocalizedStrings = Record<string, string | Record<string, string | Record<string, string | Record<string, string>>>>;
8
- export interface LanguageConfig {
9
- name: string;
10
- /**
11
- * Path to a JSON file with translated strings for this language.
12
- */
13
- path?: string;
14
- /**
15
- * A callback function that returns a Promise that resolves to the translation object for this language.
16
- */
17
- fetch?: () => Promise<LocalizedStrings>;
18
- }
19
- export type LanguageSetupOptions = {
20
- /**
21
- * Default language to load on startup
22
- */
23
- initialLanguage?: string | null;
24
- languages: LanguageConfig[];
25
- };
26
- export declare class Language {
27
- #private;
28
- $current: State<string | undefined>;
29
- constructor(dolla: Dolla);
30
- get supportedLanguages(): string[];
31
- setup(options: LanguageSetupOptions): void;
32
- setLanguage(name: string): Promise<void>;
33
- /**
34
- * Returns a State containing the value at `key`.
35
-
36
- * @param key - Key to the translated value.
37
- * @param values - A map of {{placeholder}} names and the values to replace them with.
38
- */
39
- t(key: string, values?: Record<string, Stringable | State<Stringable>>): State<string>;
40
- }
41
- export {};