Skip to content

Commit 6c9ee53

Browse files
authored
Merge pull request #4 from wuespace/fix-typo
Fix typo of `Localyzed` to `Localized`
2 parents 79fdd02 + 94261e3 commit 6c9ee53

File tree

8 files changed

+54
-54
lines changed

8 files changed

+54
-54
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LocalyzedStringValue } from "./LocalyzedStringValue.ts";
1+
import type { LocalizedStringValue } from "./LocalizedStringValue.ts";
22

33
/**
44
* A lazily evaluated localized string with a key and optional values for interpolation.
@@ -7,7 +7,7 @@ import type { LocalyzedStringValue } from "./LocalyzedStringValue.ts";
77
*
88
* Use the {@link import("lt.ts").lt} function to create instances of this type.
99
*/
10-
export type LazyLocalyzedString = {
10+
export type LazyLocalizedString = {
1111
/**
1212
* The localization key used to look up the localized string.
1313
*/
@@ -17,5 +17,5 @@ export type LazyLocalyzedString = {
1717
*
1818
* `"{i}"` gets replaced by the i-th value in this array. `"\{i}"` can be used to escape the `"{"` character.
1919
*/
20-
values: LocalyzedStringValue[];
20+
values: LocalizedStringValue[];
2121
};
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { FC } from "@hono/hono/jsx";
2-
import type { LazyLocalyzedString } from "./LazyLocalyzedString.ts";
2+
import type { LazyLocalizedString } from "./LazyLocalizedString.ts";
33

44
/**
55
* A value passed into a localized string for interpolation.
66
*
7-
* This can be a string, number, or another {@link LazyLocalyzedString} for nested localization.
7+
* This can be a string, number, or another {@link LazyLocalizedString} for nested localization.
88
*
99
* For example, given the localization entry:
1010
*
@@ -15,23 +15,23 @@ import type { LazyLocalyzedString } from "./LazyLocalyzedString.ts";
1515
* }
1616
* ```
1717
*
18-
* You could create a `LazyLocalyzedString` for `welcomeMessage` that includes another
19-
* `LazyLocalyzedString` for `greeting` as its first value:
18+
* You could create a `LazyLocalizedString` for `welcomeMessage` that includes another
19+
* `LazyLocalizedString` for `greeting` as its first value:
2020
*
2121
* ```ts
22-
* const lazyGreeting: LazyLocalyzedString = {
22+
* const lazyGreeting: LazyLocalizedString = {
2323
* localizationKey: "greeting",
2424
* values: ["Alice"]
2525
* };
2626
*
27-
* const lazyWelcomeMessage: LazyLocalyzedString = {
27+
* const lazyWelcomeMessage: LazyLocalizedString = {
2828
* localizationKey: "welcomeMessage",
2929
* values: [lazyGreeting]
3030
* };
3131
* ```
3232
*/
33-
export type LocalyzedStringValue =
33+
export type LocalizedStringValue =
3434
| string
3535
| number
36-
| LazyLocalyzedString
36+
| LazyLocalizedString
3737
| ReturnType<FC>;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { LazyLocalizedString } from "./LazyLocalizedString.ts";
2+
import type { LocalizedStringValue } from "./LocalizedStringValue.ts";
3+
import { lt } from "./lt.ts";
4+
5+
/**
6+
* Ensures that the input is a LazyLocalizedString.
7+
*
8+
* Can be applied to either a template string or an already existing LazyLocalizedString.
9+
*
10+
* @returns the input as a LazyLocalizedString
11+
*/
12+
export function ensureLazyLocalizedString(
13+
input: TemplateStringsArray | LazyLocalizedString,
14+
values: LocalizedStringValue[],
15+
): LazyLocalizedString {
16+
if (Array.isArray(input)) {
17+
return lt(input as TemplateStringsArray, ...values);
18+
} else {
19+
return input as LazyLocalizedString;
20+
}
21+
}

lib/hono/ensureLazyLocalyzedString.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/hono/ensureRequestLanguage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Context } from "@hono/hono";
2-
import { HonolateContext } from "./HonolateContext.ts";
3-
import { InitHonolateOptions } from "./InitHonolateOptions.ts";
1+
import type { Context } from "@hono/hono";
2+
import type { HonolateContext } from "./HonolateContext.ts";
3+
import type { InitHonolateOptions } from "./InitHonolateOptions.ts";
44
import { runLanguageDetector } from "./runLanguageDetector.ts";
55

66
/**

lib/hono/lt.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { escapeKey } from "../common/escapeKey.ts";
2-
import type { LazyLocalyzedString } from "./LazyLocalyzedString.ts";
3-
import type { LocalyzedStringValue } from "./LocalyzedStringValue.ts";
2+
import type { LazyLocalizedString } from "./LazyLocalizedString.ts";
3+
import type { LocalizedStringValue } from "./LocalizedStringValue.ts";
44

55
/**
6-
* A template tag function to create a {@link LazyLocalyzedString}.
7-
* @returns A {@link LazyLocalyzedString} representing the localization key and its values.
6+
* A template tag function to create a {@link LazyLocalizedString}.
7+
* @returns A {@link LazyLocalizedString} representing the localization key and its values.
88
*
99
* @example
1010
* ```ts
@@ -35,8 +35,8 @@ import type { LocalyzedStringValue } from "./LocalyzedStringValue.ts";
3535
*/
3636
export function lt(
3737
strings: TemplateStringsArray,
38-
...values: LocalyzedStringValue[]
39-
): LazyLocalyzedString {
38+
...values: LocalizedStringValue[]
39+
): LazyLocalizedString {
4040
const escaped = strings.map(escapeKey);
4141
let localizationKey = "";
4242
for (let i = 0; i < escaped.length; i++) {

lib/hono/t.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { raw } from "@hono/hono/html";
22
import type { HtmlEscapedString } from "@hono/hono/utils/html";
33
import { unescapeKey } from "../common/unescapeKey.ts";
4-
import { ensureLazyLocalyzedString } from "./ensureLazyLocalyzedString.ts";
4+
import { ensureLazyLocalizedString } from "./ensureLazyLocalizedString.ts";
55
import { getLocalizationMap } from "./getLocalizationMap.ts";
6-
import type { LazyLocalyzedString } from "./LazyLocalyzedString.ts";
7-
import type { LocalyzedStringValue } from "./LocalyzedStringValue.ts";
6+
import type { LazyLocalizedString } from "./LazyLocalizedString.ts";
7+
import type { LocalizedStringValue } from "./LocalizedStringValue.ts";
88

99
/**
1010
* Resolves a localized string based on the current localization map.
1111
1212
* @returns the localized string with placeholders filled in
1313
*
14-
* Can be used as a template string tag or as a function with a LazyLocalyzedString.
14+
* Can be used as a template string tag or as a function with a LazyLocalizedString.
1515
*
1616
* Can only be called inside a functional component. To use this directly in route handlers,
1717
* use {@link asFC} to wrap the handler as a functional component.
@@ -24,9 +24,9 @@ import type { LocalyzedStringValue } from "./LocalyzedStringValue.ts";
2424
* const greeting = t`greeting.hello.${userName}`;
2525
* ```
2626
*
27-
* @example Example with LazyLocalyzedString:
27+
* @example Example with LazyLocalizedString:
2828
* ```ts
29-
* const lls: LazyLocalyzedString = {
29+
* const lls: LazyLocalizedString = {
3030
* localizationKey: "greeting.hello",
3131
* values: [userName],
3232
* };
@@ -47,14 +47,14 @@ import type { LocalyzedStringValue } from "./LocalyzedStringValue.ts";
4747
*/
4848
export function t(
4949
strings: TemplateStringsArray,
50-
...values: LocalyzedStringValue[]
50+
...values: LocalizedStringValue[]
5151
): string | HtmlEscapedString;
5252
export function t(
53-
string: string | LazyLocalyzedString,
53+
string: string | LazyLocalizedString,
5454
): string | HtmlEscapedString;
5555
export function t(
56-
string: TemplateStringsArray | LazyLocalyzedString | string,
57-
...values: LocalyzedStringValue[]
56+
string: TemplateStringsArray | LazyLocalizedString | string,
57+
...values: LocalizedStringValue[]
5858
): string | HtmlEscapedString {
5959
if (typeof string === "string") {
6060
// simple string, return as is
@@ -63,7 +63,7 @@ export function t(
6363
values: [],
6464
};
6565
}
66-
const lls = ensureLazyLocalyzedString(string, values);
66+
const lls = ensureLazyLocalizedString(string, values);
6767
const localizationValues = getLocalizationMap();
6868

6969
if (!(lls.localizationKey in localizationValues)) {

lib/mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export { t } from "./hono/t.ts";
55
export { asFC } from "./hono/asFC.tsx";
66
export { runCLI } from "./extract/runCLI.ts";
77
export { useLocale } from "./hono/useLocale.ts";
8-
export type { LocalyzedStringValue } from "./hono/LocalyzedStringValue.ts";
9-
export type { LazyLocalyzedString } from "./hono/LazyLocalyzedString.ts";
8+
export type { LocalizedStringValue } from "./hono/LocalizedStringValue.ts";
9+
export type { LazyLocalizedString } from "./hono/LazyLocalizedString.ts";

0 commit comments

Comments
 (0)