• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript xtb.Xtb类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@angular/compiler/src/i18n/serializers/xtb.Xtb的典型用法代码示例。如果您正苦于以下问题:TypeScript Xtb类的具体用法?TypeScript Xtb怎么用?TypeScript Xtb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Xtb类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

  describe('XTB serializer', () => {
    let serializer: Xtb;

    function loadAsText(content: string, placeholders: {[id: string]: {[name: string]: string}}):
        {[id: string]: string} {
      const asAst = serializer.load(content, 'url', placeholders);
      let asText: {[id: string]: string} = {};
      Object.getOwnPropertyNames(asAst).forEach(
          id => { asText[id] = serializeAst(asAst[id]).join(''); });

      return asText;
    }

    beforeEach(() => { serializer = new Xtb(new HtmlParser(), DEFAULT_INTERPOLATION_CONFIG); });


    describe('load', () => {
      it('should load XTB files with a doctype', () => {
        const XTB = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE translationbundle [<!ELEMENT translationbundle (translation)*>
<!ATTLIST translationbundle lang CDATA #REQUIRED>

<!ELEMENT translation (#PCDATA|ph)*>
<!ATTLIST translation id CDATA #REQUIRED>

<!ELEMENT ph EMPTY>
<!ATTLIST ph name CDATA #REQUIRED>
]>
<translationbundle>
  <translation id="foo">bar</translation>
</translationbundle>`;

        expect(loadAsText(XTB, {})).toEqual({foo: 'bar'});
      });

      it('should load XTB files without placeholders', () => {
        const XTB = `<?xml version="1.0" encoding="UTF-8"?>
<translationbundle>
  <translation id="foo">bar</translation>
</translationbundle>`;

        expect(loadAsText(XTB, {})).toEqual({foo: 'bar'});
      });

      it('should load XTB files with placeholders', () => {
        const XTB = `<?xml version="1.0" encoding="UTF-8"?>
<translationbundle>
  <translation id="foo">bar<ph name="PLACEHOLDER"/><ph name="PLACEHOLDER"/></translation>
</translationbundle>`;

        expect(loadAsText(XTB, {foo: {PLACEHOLDER: '!'}})).toEqual({foo: 'bar!!'});
      });

      it('should load complex XTB files', () => {
        const XTB = `<? xml version="1.0" encoding="UTF-8" ?>
<translationbundle>
  <translation id="a">translatable element <ph name="START_BOLD_TEXT"><ex>&lt;b&gt;</ex></ph>with placeholders<ph name="CLOSE_BOLD_TEXT"><ex>&lt;/b&gt;</ex></ph> <ph name="INTERPOLATION"/></translation>
  <translation id="b">{ count, plural, =0 {<ph name="START_PARAGRAPH"><ex>&lt;p&gt;</ex></ph>test<ph name="CLOSE_PARAGRAPH"><ex>&lt;/p&gt;</ex></ph>}}</translation>
  <translation id="c" desc="d" meaning="m">foo</translation>
  <translation id="d">{ count, plural, =0 {{ sex, gender, other {<ph name="START_PARAGRAPH"><ex>&lt;p&gt;</ex></ph>deeply nested<ph name="CLOSE_PARAGRAPH"><ex>&lt;/p&gt;</ex></ph>}} }}</translation>
</translationbundle>`;

        const PLACEHOLDERS = {
          a: {
            START_BOLD_TEXT: '<b>',
            CLOSE_BOLD_TEXT: '</b>',
            INTERPOLATION: '{{ a + b }}',
          },
          b: {
            START_PARAGRAPH: '<p translated=true>',
            CLOSE_PARAGRAPH: '</p>',
          },
          d: {
            START_PARAGRAPH: '<p>',
            CLOSE_PARAGRAPH: '</p>',
          },
        };

        expect(loadAsText(XTB, PLACEHOLDERS)).toEqual({
          a: 'translatable element <b>with placeholders</b> {{ a + b }}',
          b: '{ count, plural, =0 {<p translated="true">test</p>}}',
          c: 'foo',
          d: '{ count, plural, =0 {{ sex, gender, other {<p>deeply nested</p>}} }}',
        });
      });
    });

    describe('errors', () => {
      it('should throw on nested <translationbundle>', () => {
        const XTB =
            '<translationbundle><translationbundle></translationbundle></translationbundle>';

        expect(() => {
          serializer.load(XTB, 'url', {});
        }).toThrowError(/<translationbundle> elements can not be nested/);
      });

      it('should throw on nested <translation>', () => {
        const XTB = `<translationbundle>
  <translation id="outer">
//.........这里部分代码省略.........
开发者ID:AngularLovers,项目名称:angular,代码行数:101,代码来源:xtb_spec.ts


示例2: loadAsText

    function loadAsText(content: string, placeholders: {[id: string]: {[name: string]: string}}):
        {[id: string]: string} {
      const asAst = serializer.load(content, 'url', placeholders);
      let asText: {[id: string]: string} = {};
      Object.keys(asAst).forEach(id => { asText[id] = serializeAst(asAst[id]).join(''); });

      return asText;
    }
开发者ID:chong999,项目名称:angular,代码行数:8,代码来源:xtb_spec.ts


示例3: expect

 () => { expect(() => { serializer.write({}); }).toThrow(); });
开发者ID:AngularLovers,项目名称:angular,代码行数:1,代码来源:xtb_spec.ts



注:本文中的@angular/compiler/src/i18n/serializers/xtb.Xtb类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript identifiers.assetUrl函数代码示例发布时间:2022-05-28
下一篇:
TypeScript xmb.Xmb类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap