mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #29452 -- Fixed makemessages setting charset of .pot files.
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							bc1435551c
						
					
				
				
					commit
					2bc014750a
				
			
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							| @@ -97,6 +97,7 @@ answer newbie questions, and generally made Django that much better: | |||||||
|     Baptiste Mispelon <bmispelon@gmail.com> |     Baptiste Mispelon <bmispelon@gmail.com> | ||||||
|     Barry Pederson <bp@barryp.org> |     Barry Pederson <bp@barryp.org> | ||||||
|     Bartolome Sanchez Salado <i42sasab@uco.es> |     Bartolome Sanchez Salado <i42sasab@uco.es> | ||||||
|  |     Bartosz Grabski <bartosz.grabski@gmail.com> | ||||||
|     Bashar Al-Abdulhadi |     Bashar Al-Abdulhadi | ||||||
|     Bastian Kleineidam <calvin@debian.org> |     Bastian Kleineidam <calvin@debian.org> | ||||||
|     Batiste Bieler <batiste.bieler@gmail.com> |     Batiste Bieler <batiste.bieler@gmail.com> | ||||||
|   | |||||||
| @@ -182,6 +182,7 @@ def write_pot_file(potfile, msgs): | |||||||
|         found, header_read = False, False |         found, header_read = False, False | ||||||
|         for line in pot_lines: |         for line in pot_lines: | ||||||
|             if not found and not header_read: |             if not found and not header_read: | ||||||
|  |                 if 'charset=CHARSET' in line: | ||||||
|                     found = True |                     found = True | ||||||
|                     line = line.replace('charset=CHARSET', 'charset=UTF-8') |                     line = line.replace('charset=CHARSET', 'charset=UTF-8') | ||||||
|             if not line and not found: |             if not line and not found: | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| import os | import os | ||||||
| import re | import re | ||||||
| import shutil | import shutil | ||||||
|  | import tempfile | ||||||
| import time | import time | ||||||
| import warnings | import warnings | ||||||
| from io import StringIO | from io import StringIO | ||||||
| @@ -12,7 +13,7 @@ from django.core import management | |||||||
| from django.core.management import execute_from_command_line | from django.core.management import execute_from_command_line | ||||||
| from django.core.management.base import CommandError | from django.core.management.base import CommandError | ||||||
| from django.core.management.commands.makemessages import ( | from django.core.management.commands.makemessages import ( | ||||||
|     Command as MakeMessagesCommand, |     Command as MakeMessagesCommand, write_pot_file, | ||||||
| ) | ) | ||||||
| from django.core.management.utils import find_command | from django.core.management.utils import find_command | ||||||
| from django.test import SimpleTestCase, override_settings | from django.test import SimpleTestCase, override_settings | ||||||
| @@ -394,6 +395,26 @@ class BasicExtractorTests(ExtractorTests): | |||||||
|             po_contents = fp.read() |             po_contents = fp.read() | ||||||
|             self.assertMsgStr("Größe", po_contents) |             self.assertMsgStr("Größe", po_contents) | ||||||
|  |  | ||||||
|  |     def test_pot_charset_header_is_utf8(self): | ||||||
|  |         """Content-Type: ... charset=CHARSET is replaced with charset=UTF-8""" | ||||||
|  |         msgs = ( | ||||||
|  |             '# SOME DESCRIPTIVE TITLE.\n' | ||||||
|  |             '# (some lines truncated as they are not relevant)\n' | ||||||
|  |             '"Content-Type: text/plain; charset=CHARSET\\n"\n' | ||||||
|  |             '"Content-Transfer-Encoding: 8bit\\n"\n' | ||||||
|  |             '\n' | ||||||
|  |             '#: somefile.py:8\n' | ||||||
|  |             'msgid "mañana; charset=CHARSET"\n' | ||||||
|  |             'msgstr ""\n' | ||||||
|  |         ) | ||||||
|  |         with tempfile.NamedTemporaryFile() as pot_file: | ||||||
|  |             pot_filename = pot_file.name | ||||||
|  |         write_pot_file(pot_filename, msgs) | ||||||
|  |         with open(pot_filename, 'r', encoding='utf-8') as fp: | ||||||
|  |             pot_contents = fp.read() | ||||||
|  |             self.assertIn('Content-Type: text/plain; charset=UTF-8', pot_contents) | ||||||
|  |             self.assertIn('mañana; charset=CHARSET', pot_contents) | ||||||
|  |  | ||||||
|  |  | ||||||
| class JavascriptExtractorTests(ExtractorTests): | class JavascriptExtractorTests(ExtractorTests): | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user