Skip to content

Commit

Permalink
Use lodash's setWith so it always use an object as the namespace.
Browse files Browse the repository at this point in the history
Close #72.
  • Loading branch information
fnando committed Sep 9, 2023
1 parent b345b42 commit f68a59d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions __tests__/issue72.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { I18n } from "../src/I18n";

test("works with numeric keys", () => {
const i18n = new I18n();
i18n.store({ en: { units: { l: "liter", "1": "number" } } });

expect(i18n.t("units.l")).toEqual("liter");
expect(i18n.t("units.1")).toEqual("number");
expect(i18n.t("units")).toEqual({ l: "liter", "1": "number" });
});
3 changes: 2 additions & 1 deletion src/I18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import get from "lodash/get";
import has from "lodash/has";
import set from "lodash/set";
import setWith from "lodash/setWith";

import {
DateTime,
Expand Down Expand Up @@ -258,7 +259,7 @@ export class I18n {
const map = propertyFlatList(translations);

map.forEach((path) =>
set(this.translations, path, get(translations, path)),
setWith(this.translations, path, get(translations, path), Object),
);

this.hasChanged();
Expand Down
1 change: 1 addition & 0 deletions src/lodash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export { default as flattenDeep } from "lodash/flattenDeep";
export { default as get } from "lodash/get";
export { default as has } from "lodash/has";
export { default as set } from "lodash/set";
export { default as setWith } from "lodash/setWith";

0 comments on commit f68a59d

Please sign in to comment.