feat(i18n): implement xmb serializer
This commit is contained in:
parent
2b165944ea
commit
e1f8e54e34
|
@ -20,6 +20,8 @@ dependencies:
|
||||||
protobuf: '^0.5.0'
|
protobuf: '^0.5.0'
|
||||||
source_span: '^1.0.0'
|
source_span: '^1.0.0'
|
||||||
stack_trace: '^1.1.1'
|
stack_trace: '^1.1.1'
|
||||||
|
build:
|
||||||
|
git: git@github.com:dart-lang/build.git
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
transformer_test: '^0.2.0'
|
transformer_test: '^0.2.0'
|
||||||
guinness: '^0.1.18'
|
guinness: '^0.1.18'
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import {isPresent} from 'angular2/src/facade/lang';
|
||||||
|
import {Message, id} from './message';
|
||||||
|
|
||||||
|
export function serialize(messages: Message[]): string {
|
||||||
|
let ms = messages.map((m) => _serializeMessage(m)).join("");
|
||||||
|
return `<message-bundle>${ms}</message-bundle>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _serializeMessage(m: Message): string {
|
||||||
|
let desc = isPresent(m.description) ? ` desc='${m.description}'` : "";
|
||||||
|
return `<msg id='${id(m)}'${desc}>${m.content}</msg>`;
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
import {
|
||||||
|
AsyncTestCompleter,
|
||||||
|
beforeEach,
|
||||||
|
ddescribe,
|
||||||
|
describe,
|
||||||
|
expect,
|
||||||
|
iit,
|
||||||
|
inject,
|
||||||
|
it,
|
||||||
|
xdescribe,
|
||||||
|
xit
|
||||||
|
} from 'angular2/testing_internal';
|
||||||
|
|
||||||
|
import {Message, id} from 'angular2/src/i18n/message';
|
||||||
|
import {serialize} from 'angular2/src/i18n/xmb_serializer';
|
||||||
|
|
||||||
|
export function main() {
|
||||||
|
describe('Xmb Serialization', () => {
|
||||||
|
it("should return an empty message bundle for an empty list of messages",
|
||||||
|
() => { expect(serialize([])).toEqual("<message-bundle></message-bundle>"); });
|
||||||
|
|
||||||
|
it("should serialize messages without desc", () => {
|
||||||
|
let m = new Message("content", "meaning", null);
|
||||||
|
let expected = `<message-bundle><msg id='${id(m)}'>content</msg></message-bundle>`;
|
||||||
|
expect(serialize([m])).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should serialize messages with desc", () => {
|
||||||
|
let m = new Message("content", "meaning", "description");
|
||||||
|
let expected =
|
||||||
|
`<message-bundle><msg id='${id(m)}' desc='description'>content</msg></message-bundle>`;
|
||||||
|
expect(serialize([m])).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue