Skip to content

Commit 8609bd0

Browse files
authored
feat: accept object resource custom block (#57)
1 parent 0d97925 commit 8609bd0

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/composer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export type PreCompileHandler = () => {
8484
functions: MessageFunctions
8585
}
8686

87-
export type CustomBlocks = string[] | PreCompileHandler
87+
export type CustomBlocks = Array<string | LocaleMessages> | PreCompileHandler
8888

8989
/**
9090
* Composer Options
@@ -222,7 +222,7 @@ function getLocaleMessages(
222222
// merge locale messages of i18n custom block
223223
if (isArray(__i18n)) {
224224
__i18n.forEach(raw => {
225-
ret = Object.assign(ret, JSON.parse(raw))
225+
ret = Object.assign(ret, isString(raw) ? JSON.parse(raw) : raw)
226226
})
227227
return ret
228228
}

test/composer.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,35 @@ describe('__i18n', () => {
849849
}
850850
})
851851
})
852+
853+
test('locale messages object', () => {
854+
const { messages } = createComposer({
855+
__i18n: [
856+
{ en: { hello: 'Hello,world!' } },
857+
{
858+
ja: {
859+
hello: 'こんにちは、世界!',
860+
nest: {
861+
foo: {
862+
bar: 'ばー'
863+
}
864+
}
865+
}
866+
}
867+
]
868+
})
869+
expect(messages.value).toEqual({
870+
en: { hello: 'Hello,world!' },
871+
ja: {
872+
hello: 'こんにちは、世界!',
873+
nest: {
874+
foo: {
875+
bar: 'ばー'
876+
}
877+
}
878+
}
879+
})
880+
})
852881
})
853882

854883
describe('__transrateVNode', () => {

0 commit comments

Comments
 (0)