示例#1
0
    def test_clean_string(self):
        sut = arb.ArbImporter('', '')

        mock_string = "Hello %s, you are visitor number %d on site %s having score %f"
        self.assertEqual(
            sut.clean_string(mock_string),
            "Hello %s, you are visitor number %s on site %s having score %s")
示例#2
0
    def test_run(self):
        sut = arb.ArbImporter(self.mock_matches, self.mock_destination_file)

        mock_output_arb_file = json.loads('''{
    "visitorCounterMessage": "Caro \\"{visitorName}\\",\\nsei il visitatore numero {visitorNumber}!",
    "@visitorCounterMessage": {
        "type": "text",
        "placeholders": {
            "visitorName": {},
            "visitorNumber": {}
        }
    },
    "cartMessage": "{itemCounter,plural, =0{Il tuo carrello non contiene oggetti}=1{Il tuo carrello contiene un oggetto}other{Il tuo carrello contiene {itemCounter} oggetti}}",
    "@cartMessage": {
        "type": "text",
        "placeholders": {
            "itemCounter": {}
        }
    },
    "untranslatedString": "String with missing translation",
    "@untranslatedString": {
        "type": "text",
        "placeholders": {}
    }
}''')

        sut.run()

        with open(self.mock_destination_file, 'r') as arb_file:
            built_file = json.load(arb_file)
            arb_file.close()

        self.assertEqual(built_file, mock_output_arb_file)
示例#3
0
    def test_clean_placeholders(self):
        sut = arb.ArbImporter('', '')

        mock_string = "Hello {visitorName}, you are visitor number {visitorNumber}"
        mock_placeholders = ['visitorName', 'visitorNumber']
        self.assertEqual(
            sut.clean_placeholders(mock_string, mock_placeholders),
            "Hello %s, you are visitor number %s")
示例#4
0
    def test_split_plural_strings(self):
        sut = arb.ArbImporter('', '')

        mock_multiple_string = "{howMany,plural, =0{Dear {customerName}, your cart is empty}=1{Dear {customerName}, you''ve one item in your cart}other{Dear {customerName}, you have {howMany} items in your chart}}"
        self.assertEqual(
            sut.split_plural_string(mock_multiple_string, 'howMany',
                                    ['howMany', 'customerName']),
            [{
                'plural_case': '=0',
                'string': "Dear {customerName}, your cart is empty",
                'ordered_placeholders': ['customerName']
            }, {
                'plural_case': '=1',
                'string': "Dear {customerName}, you''ve one item in your cart",
                'ordered_placeholders': ['customerName']
            }, {
                'plural_case': 'other',
                'string':
                "Dear {customerName}, you have {howMany} items in your chart",
                'ordered_placeholders': ['customerName', 'howMany']
            }])
示例#5
0
    def test_ctor(self):
        sut = arb.ArbImporter(self.mock_matches, self.mock_destination_file)

        self.assertEqual(sut.matches, self.mock_matches)
        self.assertEqual(sut.destination_file, self.mock_destination_file)
示例#6
0
    def test_get_ordered_placeholders(self):
        sut = arb.ArbImporter('', '')

        mock_string = "This string contains {placeholder1}, {placeholder2} and {placeholder3}"
        self.assertEqual(sut.get_ordered_placeholders(mock_string),
                         ['placeholder1', 'placeholder2', 'placeholder3'])