1from translate.convert import po2rc, test_convert 2from translate.storage.rc import rcfile 3 4 5RC_SOURCE = r""" 6#include "other_file.h" // This must be ignored 7 8LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT 9 10///////////////////////////////////////////////////////////////////////////// 11// 12// Dialog 13// 14 15IDD_REGGHC_DIALOG DIALOGEX 0, 0, 211, 191 16STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU 17EXSTYLE WS_EX_APPWINDOW 18CAPTION "License dialog" 19FONT 8, "MS Shell Dlg", 0, 0, 0x1 20BEGIN 21 PUSHBUTTON "Help",ID_HELP,99,162,48,15 22 PUSHBUTTON "Close",IDCANCEL,151,162,48,15 23 PUSHBUTTON "Activate instalation",IDC_BUTTON1,74,76,76,18 24 CTEXT "My very good program",IDC_STATIC1,56,21,109,19,SS_SUNKEN 25 CTEXT "You can use it without registering it",IDC_STATIC,35,131,128,19,SS_SUNKEN 26 PUSHBUTTON "Offline",IDC_OFFLINE,149,108,42,13 27 PUSHBUTTON "See license",IDC_LICENCIA,10,162,85,15 28 RTEXT "If you don't have internet, please use magic.",IDC_STATIC,23,105,120,18 29 ICON IDR_MAINFRAME,IDC_STATIC,44,74,20,20 30 CTEXT "Use your finger to activate the program.",IDC_ACTIVADA,17,50,175,17 31 ICON IDR_MAINFRAME1,IDC_STATIC6,18,19,20,20 32END 33 34MainMenu MENU 35{ 36 POPUP "&Debug" 37 { 38 MENUITEM "&Memory usage", ID_MEMORY 39 POPUP 40 { 41 MENUITEM SEPARATOR 42 MENUITEM "&Walk data heap", ID_WALK_HEAP 43 } 44 } 45} 46 47STRINGTABLE 48BEGIN 49ID_T_1 "Hello" 50END 51""" 52 53POFILE = """ 54#: DIALOGEX.IDD_REGGHC_DIALOG.CAPTION 55msgid "License dialog" 56msgstr "Licenční dialog" 57""" 58 59 60class TestPO2RCCommand(test_convert.TestConvertCommand): 61 """Tests running actual po2rc commands on files""" 62 63 convertmodule = po2rc 64 defaultoptions = {"progress": "none"} 65 66 def test_help(self, capsys): 67 """tests getting help""" 68 options = super().test_help(capsys) 69 options = self.help_check(options, "-t TEMPLATE, --template=TEMPLATE") 70 options = self.help_check(options, "-l LANG, --lang=LANG") 71 72 def test_convert(self): 73 """Tests the conversion to a po file""" 74 self.create_testfile("simple.rc", RC_SOURCE) 75 self.create_testfile("simple.po", POFILE) 76 self.run_command( 77 template="simple.rc", i="simple.po", o="output.rc", l="LANG_CZECH" 78 ) 79 with self.open_testfile("output.rc") as handle: 80 rc_result = rcfile(handle) 81 assert len(rc_result.units) == 14 82 assert rc_result.units[0].target == "Licenční dialog" 83 84 def test_convert_comment(self): 85 self.create_testfile( 86 "simple.rc", 87 """ 88STRINGTABLE 89BEGIN 90 // IDS_COMMENTED "Comment" 91 IDS_COPIED "Copied" 92END 93""", 94 ) 95 self.create_testfile( 96 "simple.po", 97 """ 98#: STRINGTABLE.IDS_COPIED 99msgid "Copied" 100msgstr "Zkopirovano" 101""", 102 ) 103 self.run_command( 104 template="simple.rc", i="simple.po", o="output.rc", l="LANG_CZECH" 105 ) 106 with self.open_testfile("output.rc") as handle: 107 rc_result = rcfile(handle) 108 assert len(rc_result.units) == 1 109 assert rc_result.units[0].target == "Zkopirovano" 110 111 def test_convert_comment_dos_eol(self): 112 self.create_testfile( 113 "simple.rc", 114 b"""\r\nSTRINGTABLE\r\nBEGIN\r\n// Comment\r\nIDS_1 "Copied"\r\nEND\r\n""", 115 ) 116 self.create_testfile( 117 "simple.po", 118 """ 119#: STRINGTABLE.IDS_1 120msgid "Copied" 121msgstr "Zkopirovano" 122""", 123 ) 124 self.run_command( 125 template="simple.rc", i="simple.po", o="output.rc", l="LANG_CZECH" 126 ) 127 with self.open_testfile("output.rc", "rb") as handle: 128 content = handle.read() 129 assert ( 130 content 131 == b"""\r\nSTRINGTABLE\r\nBEGIN\r\n // Comment\r\n IDS_1 "Zkopirovano"\r\nEND\r\n""" 132 ) 133 with self.open_testfile("output.rc") as handle: 134 rc_result = rcfile(handle) 135 assert len(rc_result.units) == 1 136 assert rc_result.units[0].target == "Zkopirovano" 137