示例#1
0
    def test_concat_two(self):
        msg = FTL.Entity(
            FTL.Identifier('hello'),
            value=CONCAT(
                LITERAL_FROM(self.strings, 'hello.start'),
                LITERAL_FROM(self.strings, 'hello.end'),
            )
        )

        result = evaluate(self, msg)

        self.assertEqual(
            len(result.value.elements),
            1,
            'The constructed value should have only one element'
        )
        self.assertIsInstance(
            result.value.elements[0],
            FTL.TextElement,
            'The constructed element should be a TextElement.'
        )
        self.assertEqual(
            result.value.elements[0].value,
            'Hello, world!',
            'The TextElement should be a concatenation of the sources.'
        )

        self.assertEqual(
            result.toJSON(),
            ftl_message_to_json('''
                hello = Hello, world!
            ''')
        )
示例#2
0
 def test_plural_too_many_variants(self):
     self.plural_categories = ('one',)
     self.assertEqual(
         evaluate(self, self.message).toJSON(),
         ftl_message_to_json('''
             delete-all = { $num ->
                *[one] Delete this download?
             }
         ''')
     )
示例#3
0
 def test_plural(self):
     self.assertEqual(
         evaluate(self, self.message).toJSON(),
         ftl_message_to_json('''
             delete-all = { $num ->
                 [one] Delete this download?
                *[other] Delete all downloads?
             }
         ''')
     )
示例#4
0
 def test_plural_too_few_variants(self):
     self.plural_categories = ('one', 'few', 'many', 'other')
     self.assertEqual(
         evaluate(self, self.message).toJSON(),
         ftl_message_to_json('''
             delete-all = { $num ->
                 [one] Delete this download?
                *[few] Delete all downloads?
             }
         ''')
     )
示例#5
0
    def test_copy_html_entity(self):
        msg = FTL.Entity(
            FTL.Identifier('foo-html-entity'),
            value=LITERAL_FROM(self.strings, 'foo.html.entity')
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                foo-html-entity = <⇧⌘K>
            ''')
        )
示例#6
0
    def test_copy_escape_unicode_end(self):
        msg = FTL.Entity(
            FTL.Identifier('foo-unicode-end'),
            value=LITERAL_FROM(self.strings, 'foo.unicode.end')
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                foo-unicode-end = "Foo "
            ''')
        )
示例#7
0
    def test_copy(self):
        msg = FTL.Entity(
            FTL.Identifier('foo'),
            value=LITERAL_FROM(self.strings, 'foo')
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                foo = Foo
            ''')
        )
示例#8
0
    def test_concat_one(self):
        msg = FTL.Entity(
            FTL.Identifier('hello'),
            value=CONCAT(
                LITERAL_FROM(self.strings, 'hello'),
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                hello = Hello, world!
            ''')
        )
示例#9
0
    def test_concat_whitespace_end(self):
        msg = FTL.Entity(
            FTL.Identifier('hello'),
            value=CONCAT(
                LITERAL_FROM(self.strings, 'whitespace.end.start'),
                LITERAL_FROM(self.strings, 'whitespace.end.end'),
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                hello = "Hello, world! "
            ''')
        )
示例#10
0
    def test_replace_last(self):
        msg = FTL.Entity(
            FTL.Identifier(u'last'),
            value=REPLACE_FROM(
                self.strings,
                'last',
                {'#1': [FTL.ExternalArgument(u'bar')]}
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                last = Foo { $bar }
            ''')
        )
示例#11
0
    def test_concat_replace(self):
        msg = FTL.Entity(
            FTL.Identifier('channel-desc'),
            value=CONCAT(
                LITERAL_FROM(self.strings, 'channel.description.start'),
                EXTERNAL('channelname'),
                LITERAL_FROM(self.strings, 'channel.description.end'),
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                channel-desc = "You are on the { $channelname } channel. "
            ''')
        )
示例#12
0
    def test_replace_too_few(self):
        msg = FTL.Entity(
            FTL.Identifier(u'welcome'),
            value=REPLACE_FROM(
                self.strings,
                'welcome',
                {'#1': [FTL.ExternalArgument(u'username')]}
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                welcome = Welcome, { $username }, to #2!
            ''')
        )
示例#13
0
    def test_replace_one(self):
        msg = FTL.Entity(
            FTL.Identifier(u'hello'),
            value=REPLACE_FROM(
                self.strings,
                'hello',
                {'#1': [FTL.ExternalArgument(u'username')]}
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                hello = Hello, { $username }!
            ''')
        )
示例#14
0
    def test_concat_literal(self):
        msg = FTL.Entity(
            FTL.Identifier('update-failed'),
            value=CONCAT(
                LITERAL_FROM(self.strings, 'update.failed.start'),
                LITERAL('<a>'),
                LITERAL_FROM(self.strings, 'update.failed.linkText'),
                LITERAL('</a>'),
                LITERAL_FROM(self.strings, 'update.failed.end'),
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                update-failed = Update failed. <a>Download manually</a>!
            ''')
        )
示例#15
0
    def test_concat_replace(self):
        msg = FTL.Entity(
            FTL.Identifier('community'),
            value=CONCAT(
                REPLACE_FROM(
                    self.strings,
                    'community.start',
                    {
                        '&brandShortName;': [
                            FTL.ExternalArgument('brand-short-name')
                        ]
                    }
                ),
                LITERAL('<a>'),
                REPLACE_FROM(
                    self.strings,
                    'community.mozillaLink',
                    {
                        '&vendorShortName;': [
                            FTL.ExternalArgument('vendor-short-name')
                        ]
                    }
                ),
                LITERAL('</a>'),
                LITERAL_FROM(self.strings, 'community.middle'),
                LITERAL('<a>'),
                LITERAL_FROM(self.strings, 'community.creditsLink'),
                LITERAL('</a>'),
                LITERAL_FROM(self.strings, 'community.end')
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json(
                'community = { $brand-short-name } is designed by '
                '<a>{ $vendor-short-name }</a>, a <a>global community</a> '
                'working together to…'
            )
        )
示例#16
0
    def test_plural_replace(self):
        msg = FTL.Entity(
            FTL.Identifier('delete-all'),
            value=PLURALS_FROM(
                self.strings,
                'deleteAll',
                FTL.ExternalArgument('num'),
                lambda var: REPLACE(
                    var,
                    {'#1': [FTL.ExternalArgument('num')]}
                )
            )
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                delete-all = { $num ->
                    [one] Delete this download?
                   *[other] Delete { $num } downloads?
                }
            ''')
        )
示例#17
0
    def test_copy_accesskey(self):
        msg = FTL.Entity(
            FTL.Identifier('check-for-updates'),
            traits=[
                FTL.Member(
                    FTL.Keyword('label', 'xul'),
                    LITERAL_FROM(self.strings, 'checkForUpdatesButton.label')
                ),
                FTL.Member(
                    FTL.Keyword('accesskey', 'xul'),
                    LITERAL_FROM(self.strings, 'checkForUpdatesButton.accesskey')
                ),
            ]
        )

        self.assertEqual(
            evaluate(self, msg).toJSON(),
            ftl_message_to_json('''
                check-for-updates =
                  [xul/label] Check for updates
                  [xul/accesskey] C
            ''')
        )