Skip to content

Commit

Permalink
fix(cli): handling numbers in unlocalizable loader (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathio authored Feb 27, 2025
1 parent 6cf9f0d commit f0c7f6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-cameras-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"lingo.dev": patch
---

fix handling numbers in unlocalizable loader
10 changes: 9 additions & 1 deletion packages/cli/src/cli/loaders/unlocalizable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ describe("unlocalizable loader", () => {
const data = {
foo: "bar",
num: 1,
numStr: "1.0",
empty: "",
bool: true,
boolStr: "false",
isoDate: "2025-02-21",
isoDateTime: "2025-02-21T00:00:00.000Z",
bar: "foo",
url: "https://example.com",
systemId: "Ab1cdefghijklmnopqrst2",
Expand All @@ -19,7 +22,12 @@ describe("unlocalizable loader", () => {
loader.setDefaultLocale("en");
const result = await loader.pull("en", data);

expect(result).toEqual({ foo: "bar", bar: "foo" });
expect(result).toEqual({
foo: "bar",
numStr: "1.0",
boolStr: "false",
bar: "foo",
});
});

it("should handle unlocalizable keys on push", async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/cli/loaders/unlocalizable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export default function createUnlocalizableLoader(
): ILoader<Record<string, any>, Record<string, any>> {
const rules = {
isEmpty: (v: any) => _.isEmpty(v),
isNumber: (v: string) => !_.isNaN(_.toNumber(v)),
isBoolean: (v: string) => _.isBoolean(v),
isIsoDate: (v: string) => _.isString(v) && _isIsoDate(v),
isSystemId: (v: string) => _.isString(v) && _isSystemId(v),
isUrl: (v: string) => _.isString(v) && _isUrl(v),
isNumber: (v: any) => typeof v === "number" || /^[0-9]+$/.test(v),
isBoolean: (v: any) => _.isBoolean(v),
isIsoDate: (v: any) => _.isString(v) && _isIsoDate(v),
isSystemId: (v: any) => _.isString(v) && _isSystemId(v),
isUrl: (v: any) => _.isString(v) && _isUrl(v),
};
return createLoader({
async pull(locale, input) {
Expand Down

0 comments on commit f0c7f6e

Please # to comment.