Skip to content

Commit

Permalink
feat: accept object resource custom block (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Jun 3, 2020
1 parent 0d97925 commit 8609bd0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export type PreCompileHandler = () => {
functions: MessageFunctions
}

export type CustomBlocks = string[] | PreCompileHandler
export type CustomBlocks = Array<string | LocaleMessages> | PreCompileHandler

/**
* Composer Options
Expand Down Expand Up @@ -222,7 +222,7 @@ function getLocaleMessages(
// merge locale messages of i18n custom block
if (isArray(__i18n)) {
__i18n.forEach(raw => {
ret = Object.assign(ret, JSON.parse(raw))
ret = Object.assign(ret, isString(raw) ? JSON.parse(raw) : raw)
})
return ret
}
Expand Down
29 changes: 29 additions & 0 deletions test/composer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,35 @@ describe('__i18n', () => {
}
})
})

test('locale messages object', () => {
const { messages } = createComposer({
__i18n: [
{ en: { hello: 'Hello,world!' } },
{
ja: {
hello: 'こんにちは、世界!',
nest: {
foo: {
bar: 'ばー'
}
}
}
}
]
})
expect(messages.value).toEqual({
en: { hello: 'Hello,world!' },
ja: {
hello: 'こんにちは、世界!',
nest: {
foo: {
bar: 'ばー'
}
}
}
})
})
})

describe('__transrateVNode', () => {
Expand Down

0 comments on commit 8609bd0

Please sign in to comment.