def test_plural(self): source = '''key = { $number -> [1] Simple String *[other] Other Simple String }''' assert_equal(as_simple_translation(source), 'Other Simple String')
def test_attribute_select_expression(self): source = '''key .placeholder = { PLATFORM() -> [win] Simple String *[other] Other Simple String }''' assert_equal(as_simple_translation(source), 'Other Simple String')
def test_multiline(self): source = '''key = Simple String In Multiple Lines''' assert_equal(as_simple_translation(source), 'Simple String\nIn Multiple\nLines')
def simplify_ftl_tm_entries(apps, schema): """ Reformat all FTL source strings and translations in TranslationMemoryEntry table with as_simple_translation(). See bug 1576120 for more details. """ TranslationMemoryEntry = apps.get_model("base", "TranslationMemoryEntry") tm_entries = TranslationMemoryEntry.objects.filter(entity__resource__format="ftl") for tme in tm_entries: tme.source = as_simple_translation(tme.source) tme.target = as_simple_translation(tme.target) bulk_update( tm_entries, update_fields=["source", "target"], batch_size=1000, )
def test_wrapped_select_expression(self): source = '''key = Anne liked your comment on { $photo_count -> [male] his [female] her *[other] their } post.''' assert_equal(as_simple_translation(source), 'Anne liked your comment on their post.')
def regenerate_ftl_entries_with_comments(apps, schema): """ Regenerate source column in TranslationMemoryEntry for all FTL strings that are potentially comments instead of strings. See bug 1581594 for more details. """ TranslationMemoryEntry = apps.get_model('base', 'TranslationMemoryEntry') tm_entries = (TranslationMemoryEntry.objects.filter( entity__resource__format='ftl', source__contains="#").prefetch_related('entity', 'translation')) for tme in tm_entries: tme.source = as_simple_translation(tme.entity.string) bulk_update( tm_entries, update_fields=['source', 'target'], batch_size=1000, )
def test_helper_as_simple_translation(k): string, expected = SIMPLE_TRANSLATION_TESTS[k] assert as_simple_translation(string) == expected
def test_simple(self): source = 'key = Simple String' assert_equal(as_simple_translation(source), 'Simple String')
def test_non_ftl(self): source = 'Simple String' assert_equal(as_simple_translation(source), 'Simple String')
def test_empty_string(self): source = '' assert_equal(as_simple_translation(source), '')
def test_other_ftl(self): source = 'warning-upgrade = { LINK("Link text", title: "Link title") }Simple String' assert_equal(as_simple_translation(source), 'Simple String')
def test_attributes(self): source = '''key .attribute = Simple String .other = Other Simple String''' assert_equal(as_simple_translation(source), 'Simple String')
def test_attribute(self): source = '''key .placeholder = Simple String''' assert_equal(as_simple_translation(source), 'Simple String')