def test_view_tmx_valid_entries(): data_root = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data", ) filepath = "tmx/valid_entries.tmx" with open(os.path.join(data_root, filepath), encoding="utf-8") as f: xml = f.read() tmx_contents = build_translation_memory_file( datetime(2010, 1, 1), "sl", ( ( "aa/bb/ccc", "xxx", "source string", "translation", "pontoon", ), # Test escape of characters ( "aa/bb/ccc", 'x&y&z#"', "source string", "translation", "pontoon", ), # Handle unicode characters ( "aa/bb/ccc", "xxx", "source string łążśźć", "translation łążśźć", "pontoon", ), # Handle html content ( "aa/bb/ccc", "xxx", "<p>source <strong>string</p>", "<p>translation łążśźć</p>", "pontoon", ), # Handle illegal characters ( "aa/bb/ccc", "xxx", "content are c.1998–2019", "content are c.1998–2019", "pontoon", ), ), ) _check_xml( "".join(tmx_contents).encode("utf-8"), xml, os.path.join(data_root, "tmx/tmx14.dtd"), )
def download_translation_memory(request, locale, slug, filename): locale = get_object_or_404(Locale, code=locale) if slug.lower() == 'all-projects': project_filter = Q() else: project = get_object_or_404(Project.objects.available(), slug=slug) project_filter = Q(project=project) tm_entries = (TranslationMemoryEntry.objects.filter(project_filter).filter( locale=locale, translation__isnull=False).exclude(Q(source='') | Q(target='')).exclude( translation__approved=False, translation__fuzzy=False)) filename = '{code}.{slug}.tmx'.format(code=locale.code, slug=slug) response = StreamingHttpResponse(utils.build_translation_memory_file( datetime.now(), locale.code, tm_entries.values_list('entity__resource__path', 'entity__key', 'source', 'target', 'project__name', 'project__slug').order_by( 'project__slug', 'source')), content_type='text/xml') response[ 'Content-Disposition'] = 'attachment; filename="{filename}"'.format( filename=filename) return response
def download_translation_memory(request, locale, slug, filename): locale = get_object_or_404(Locale, code=locale) project = get_object_or_404(Project, slug=slug) tm_entries = ( TranslationMemoryEntry.objects.filter( locale=locale, project=project, translation__isnull=False, ).exclude(Q(source='') | Q(target='')) ) filename = '{code}.{slug}.tmx'.format(code=locale.code, slug=project.slug) response = StreamingHttpResponse( build_translation_memory_file( datetime.now(), locale.code, tm_entries.values_list( 'entity__resource__path', 'entity__key', 'source', 'target', 'project__name', 'project__slug' ).order_by('project__slug', 'source') ), content_type='text/xml' ) response['Content-Disposition'] = 'attachment; filename="{filename}"'.format(filename=filename) return response
def test_view_tmx_valid_entries(): data_root = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'data', ) filepath = 'tmx/valid_entries.tmx' with open(os.path.join(data_root, filepath), 'rU') as f: xml = f.read().decode('utf-8') tmx_contents = build_translation_memory_file( datetime(2010, 1, 1), 'sl', ( ( 'aa/bb/ccc', 'xxx', 'source string', 'translation', 'Pontoon App', 'pontoon', ), # Test escape of characters ( 'aa/bb/ccc', 'x&x&x#"', 'source string', 'translation', 'Pontoon & App', 'pontoon', ), # Handle unicode characters ( 'aa/bb/ccc', 'xxx', u'source string łążśźć', u'translation łążśźć', 'pontoon', 'pontoon', ), # Handle html content ( 'aa/bb/ccc', 'xxx', u'<p>source <strong>string</p>', u'<p>translation łążśźć</p>', 'pontoon', 'pontoon', ), ) ) _check_xml( ''.join(tmx_contents).encode('utf-8'), xml, os.path.join(data_root, 'tmx/tmx14.dtd'), )
def test_empty_tmx_file(self): tmx_contents = build_translation_memory_file( datetime(2010, 01, 01), 'sl', () ) assert_xml( ''.join(tmx_contents).encode('utf-8'), self.get_sample('tmx/no_entries.tmx'), os.path.join(self.samples_root, 'tmx/tmx14.dtd') )
def test_view_tmx_empty_file(): data_root = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data", ) filepath = "tmx/no_entries.tmx" with open(os.path.join(data_root, filepath), encoding="utf-8") as f: xml = f.read() tmx_contents = build_translation_memory_file(datetime(2010, 1, 1), "sl", ()) _check_xml( "".join(tmx_contents).encode("utf-8"), xml, os.path.join(data_root, "tmx/tmx14.dtd"), )
def test_view_tmx_empty_file(): data_root = os.path.join( os.path.dirname(os.path.abspath(__file__)), 'data', ) filepath = 'tmx/no_entries.tmx' with open(os.path.join(data_root, filepath), 'rU') as f: xml = f.read().decode('utf-8') tmx_contents = build_translation_memory_file(datetime(2010, 1, 1), 'sl', ()) _check_xml( ''.join(tmx_contents).encode('utf-8'), xml, os.path.join(data_root, 'tmx/tmx14.dtd'), )
def download_translation_memory(request, locale, slug): locale = get_object_or_404(Locale, code=locale) if slug.lower() == "all-projects": project_filter = Q() else: project = get_object_or_404( Project.objects.visible_for(request.user).available(), slug=slug ) project_filter = Q(project=project) tm_entries = ( TranslationMemoryEntry.objects.filter(project_filter) .filter(locale=locale, translation__isnull=False) .exclude(Q(source="") | Q(target="")) .exclude(translation__approved=False, translation__fuzzy=False) ) filename = "{code}.{slug}.tmx".format(code=locale.code, slug=slug) response = StreamingHttpResponse( utils.build_translation_memory_file( datetime.now(), locale.code, tm_entries.values_list( "entity__resource__path", "entity__key", "source", "target", "project__name", "project__slug", ).order_by("project__slug", "source"), ), content_type="text/xml", ) response["Content-Disposition"] = 'attachment; filename="{filename}"'.format( filename=filename ) return response
def test_valid_entries(self): tmx_contents = build_translation_memory_file( datetime(2010, 01, 01), 'sl', ( ('aa/bb/ccc', 'xxx', 'source string', 'translation', 'Pontoon App', 'pontoon'), # Test escape of characters ('aa/bb/ccc', 'x&x&x#"', 'source string', 'translation', 'Pontoon & App', 'pontoon'), # Handle unicode characters ('aa/bb/ccc', 'xxx', u'source string łążśźć', u'translation łążśźć', 'pontoon', 'pontoon'), # Handle html content ('aa/bb/ccc', 'xxx', u'<p>source <strong>string</p>', u'<p>translation łążśźć</p>', 'pontoon', 'pontoon'), ) ) assert_xml( ''.join(tmx_contents).encode('utf-8'), self.get_sample('tmx/valid_entries.tmx'), os.path.join(self.samples_root, 'tmx/tmx14.dtd') )