Ticket #7167: stxtinfo-localization.patch
File stxtinfo-localization.patch, 17.0 KB (added by , 13 years ago) |
---|
-
src/tools/translation/stxtinfo/stxtinfo.cpp
48 48 #include <stdlib.h> 49 49 #include <string.h> 50 50 #include <ByteOrder.h> 51 #include <Catalog.h> 51 52 #include <File.h> 52 53 #include <TranslatorFormats.h> 53 54 #include <Font.h> … … 55 56 #include <fs_attr.h> 56 57 // for attr_info 57 58 59 #undef B_TRANSLATE_CONTEXT 60 #define B_TRANSLATE_CONTEXT "stxtinfo" 61 58 62 #define max(x,y) ((x > y) ? x : y) 59 63 #define DATA_BUFFER_SIZE 64 60 64 … … 87 91 style.face = B_BENDIAN_TO_HOST_INT16(style.face); 88 92 style.reserved = B_BENDIAN_TO_HOST_INT16(style.reserved); 89 93 90 printf( "\nStyle %d:\n", static_cast<int>(i + 1));91 printf( "offset: %d\n", static_cast<int>(style.offset));92 printf( "family: %s\n", style.family);93 printf( "style: %s\n", style.style);94 printf( "size: %f\n", style.size);95 printf( "shear: %f (typically 90.0)\n", style.shear);96 printf( "face: %u (typically 0)\n",94 printf(B_TRANSLATE("\nStyle %d:\n"), static_cast<int>(i + 1)); 95 printf(B_TRANSLATE("offset: %d\n"), static_cast<int>(style.offset)); 96 printf(B_TRANSLATE("family: %s\n"), style.family); 97 printf(B_TRANSLATE("style: %s\n"), style.style); 98 printf(B_TRANSLATE("size: %f\n"), style.size); 99 printf(B_TRANSLATE("shear: %f (typically 90.0)\n"), style.shear); 100 printf(B_TRANSLATE("face: %u (typically 0)\n"), 97 101 static_cast<unsigned int>(style.face)); 98 printf( "RGBA: (%u, %u, %u, %u)\n",102 printf(B_TRANSLATE("RGBA: (%u, %u, %u, %u)\n"), 99 103 static_cast<unsigned int>(style.red), 100 104 static_cast<unsigned int>(style.blue), 101 105 static_cast<unsigned int>(style.green), 102 106 static_cast<unsigned int>(style.alpha)); 103 printf( "reserved: %u (should be 0)\n",107 printf(B_TRANSLATE("reserved: %u (should be 0)\n"), 104 108 static_cast<unsigned int>(style.reserved)); 105 109 } 106 110 … … 113 117 if (file.GetAttrInfo(kAttrName, &info) != B_OK) 114 118 return false; 115 119 if (info.type != B_RAW_TYPE) { 116 printf( "Error: styles attribute is of the wrong type\n");120 printf(B_TRANSLATE("Error: styles attribute is of the wrong type\n")); 117 121 return false; 118 122 } 119 123 if (info.size < 160) { 120 printf( "Error: styles attribute is missing information\n");124 printf(B_TRANSLATE("Error: styles attribute is missing information\n")); 121 125 return false; 122 126 } 123 127 124 128 uint8 *pflatRunArray = new uint8[info.size]; 125 129 if (!pflatRunArray) { 126 printf("Error: Not enough memory available to read styles attribute\n"); 130 printf(B_TRANSLATE("Error: Not enough memory available to read styles " 131 "attribute\n")); 127 132 return false; 128 133 } 129 134 130 135 ssize_t amtread = file.ReadAttr(kAttrName, B_RAW_TYPE, 0, 131 136 pflatRunArray, info.size); 132 137 if (amtread != info.size) { 133 printf( "Error: Unable to read styles attribute\n");138 printf(B_TRANSLATE("Error: Unable to read styles attribute\n")); 134 139 return false; 135 140 } 136 141 … … 139 144 memcpy(&stylesheader, pflatRunArray, sizeof(StylesHeader)); 140 145 if (swap_data(B_UINT32_TYPE, &stylesheader, sizeof(StylesHeader), 141 146 B_SWAP_BENDIAN_TO_HOST) != B_OK) { 142 printf("Error: Unable to swap byte order of styles header\n"); 147 printf(B_TRANSLATE("Error: Unable to swap byte order of styles " 148 "header\n")); 143 149 return false; 144 150 } 145 151 146 152 // Print StylesHeader info 147 printf( "\"styles\" attribute data:\n\n");153 printf(B_TRANSLATE("\"styles\" attribute data:\n\n")); 148 154 149 printf("magic number: 0x%.8lx ",150 static_cast<unsigned long>(stylesheader.magic));151 155 if (stylesheader.magic == 'Ali!') 152 printf("(valid)\n"); 156 printf(B_TRANSLATE("magic number: 0x%.8lx (valid)\n"), 157 static_cast<unsigned long>(stylesheader.magic)); 153 158 else 154 printf("(INVALID, should be 0x%.8lx)\n", 159 printf(B_TRANSLATE("magic number: 0x%.8lx (INVALID, should be " 160 "0x%.8lx)\n"), static_cast<unsigned long>(stylesheader.magic), 155 161 static_cast<unsigned long>('Ali!')); 156 162 157 printf("version: 0x%.8lx ",158 static_cast<unsigned long>(stylesheader.version));159 163 if (stylesheader.version == 0) 160 printf("(valid)\n"); 164 printf(B_TRANSLATE("version: 0x%.8lx (valid)\n"), 165 static_cast<unsigned long>(stylesheader.version)); 161 166 else 162 printf("(INVALID, should be 0x%.8lx)\n", 0UL); 167 printf(B_TRANSLATE("version: 0x%.8lx (INVALID, should be 0x%.8lx)\n"), 168 static_cast<unsigned long>(stylesheader.version), 0UL); 163 169 164 printf( "number of styles: %d\n",170 printf(B_TRANSLATE("number of styles: %d\n"), 165 171 static_cast<int>(stylesheader.count)); 166 172 167 173 // Check and Print out each style … … 189 195 status_t nread = 0; 190 196 nread = file.Read(buffer, kstxtsize); 191 197 if (nread != static_cast<status_t>(kstxtsize)) { 192 printf( "Error: Unable to read stream header\n");198 printf(B_TRANSLATE("Error: Unable to read stream header\n")); 193 199 return false; 194 200 } 195 201 TranslatorStyledTextStreamHeader stxtheader; 196 202 memcpy(&stxtheader, buffer, kstxtsize); 197 203 if (swap_data(B_UINT32_TYPE, &stxtheader, kstxtsize, 198 204 B_SWAP_BENDIAN_TO_HOST) != B_OK) { 199 printf("Error: Unable to swap byte order of stream header\n"); 205 printf(B_TRANSLATE("Error: Unable to swap byte order of stream " 206 "header\n")); 200 207 return false; 201 208 } 202 209 203 210 if (stxtheader.header.magic != B_STYLED_TEXT_FORMAT) { 204 printf("Styled text magic number is incorrect, aborting.\n"); 211 printf(B_TRANSLATE("Styled text magic number is incorrect, " 212 "aborting.\n")); 205 213 return false; 206 214 } 207 215 208 216 // Print Stream Header (STXT) 209 printf( "Stream Header (STXT section):\n\n");217 printf(B_TRANSLATE("Stream Header (STXT section):\n\n")); 210 218 211 printf("magic number: 0x%.8lx ", stxtheader.header.magic);212 219 if (stxtheader.header.magic == B_STYLED_TEXT_FORMAT) 213 printf("(valid)\n"); 220 printf(B_TRANSLATE("magic number: 0x%.8lx (valid)\n"), 221 static_cast<unsigned long>(stxtheader.header.magic)); 214 222 else 215 printf("(INVALID, should be 0x%.8lx)\n", 223 printf(B_TRANSLATE("magic number: 0x%.8lx (INVALID, should be " 224 "0x%.8lx)\n"), static_cast<unsigned long>(stxtheader.header.magic), 216 225 static_cast<unsigned long>(B_STYLED_TEXT_FORMAT)); 217 226 218 printf("header size: %u ", 227 if (stxtheader.header.header_size == kstxtsize) 228 printf(B_TRANSLATE("header size: %u (valid)\n"), 219 229 static_cast<unsigned int>(stxtheader.header.header_size)); 220 if (stxtheader.header.header_size == kstxtsize)221 printf("(valid)\n");222 230 else 223 printf("(INVALID, should be %u)\n", 231 printf(B_TRANSLATE("header size: %u (INVALID, should be %u)\n"), 232 static_cast<unsigned int>(stxtheader.header.header_size), 224 233 static_cast<unsigned int>(kstxtsize)); 225 234 226 printf("data size: %u ",227 static_cast<unsigned int>(stxtheader.header.data_size));228 235 if (stxtheader.header.data_size == 0) 229 printf("(valid)\n"); 236 printf(B_TRANSLATE("data size: %u (valid)\n"), 237 static_cast<unsigned int>(stxtheader.header.data_size)); 230 238 else 231 printf("(INVALID, should be 0)\n"); 239 printf(B_TRANSLATE("data size: %u (INVALID, should be 0)\n"), 240 static_cast<unsigned int>(stxtheader.header.data_size)); 232 241 233 printf("version: %d ",234 static_cast<int>(stxtheader.version));235 242 if (stxtheader.version == 100) 236 printf("(valid)\n"); 243 printf(B_TRANSLATE("version: %d (valid)\n"), 244 static_cast<int>(stxtheader.version)); 237 245 else 238 printf("(INVALID, should be 100)\n"); 246 printf(B_TRANSLATE("version: %d (INVALID, should be 100)\n"), 247 static_cast<int>(stxtheader.version)); 239 248 240 249 241 250 // Check the TEXT header 242 251 TranslatorStyledTextTextHeader txtheader; 243 252 if (file.Read(buffer, ktxtsize) != static_cast<ssize_t>(ktxtsize)) { 244 printf( "Error: Unable to read text header\n");253 printf(B_TRANSLATE("Error: Unable to read text header\n")); 245 254 return false; 246 255 } 247 256 memcpy(&txtheader, buffer, ktxtsize); 248 257 if (swap_data(B_UINT32_TYPE, &txtheader, ktxtsize, 249 258 B_SWAP_BENDIAN_TO_HOST) != B_OK) { 250 printf("Error: Unable to swap byte order of text header\n"); 259 printf(B_TRANSLATE("Error: Unable to swap byte order of text " 260 "header\n")); 251 261 return false; 252 262 } 253 263 254 264 // Print Text Header (TEXT) 255 printf( "\nText Header (TEXT section):\n\n");265 printf(B_TRANSLATE("\nText Header (TEXT section):\n\n")); 256 266 257 printf("magic number: 0x%.8lx ", txtheader.header.magic);258 267 if (txtheader.header.magic == 'TEXT') 259 printf("(valid)\n"); 268 printf(B_TRANSLATE("magic number: 0x%.8lx (valid)\n"), 269 static_cast<unsigned long>(txtheader.header.magic)); 260 270 else 261 printf("(INVALID, should be 0x%.8lx)\n", 271 printf(B_TRANSLATE("magic number: 0x%.8lx (INVALID, should be " 272 "0x%.8lx)\n"), static_cast<unsigned long>(txtheader.header.magic), 262 273 static_cast<unsigned long>('TEXT')); 263 274 264 printf("header size: %u ",265 static_cast<unsigned int>(txtheader.header.header_size));266 275 if (stxtheader.header.header_size == ktxtsize) 267 printf("(valid)\n"); 276 printf(B_TRANSLATE("header size: %u (valid)\n"), 277 static_cast<unsigned int>(txtheader.header.header_size)); 268 278 else 269 printf("(INVALID, should be %u)\n", 279 printf(B_TRANSLATE("header size: %u (INVALID, should be %u)\n"), 280 static_cast<unsigned int>(txtheader.header.header_size), 270 281 static_cast<unsigned int>(ktxtsize)); 271 282 272 printf( "data size (bytes of text): %u\n",283 printf(B_TRANSLATE("data size (bytes of text): %u\n"), 273 284 static_cast<unsigned int>(txtheader.header.data_size)); 274 285 275 printf("character set: %d ",276 static_cast<int>(txtheader.charset));277 286 if (txtheader.charset == B_UNICODE_UTF8) 278 printf("(valid)\n"); 287 printf(B_TRANSLATE("character set: %d (valid)\n"), 288 static_cast<int>(txtheader.charset)); 279 289 else 280 printf("(INVALID, should be %d)\n", B_UNICODE_UTF8); 290 printf(B_TRANSLATE("character set: %d (INVALID, should be %d)\n"), 291 static_cast<int>(txtheader.charset), B_UNICODE_UTF8); 281 292 282 293 // Skip the text data 283 294 off_t seekresult, pos; … … 286 297 txtheader.header.data_size; 287 298 seekresult = file.Seek(txtheader.header.data_size, SEEK_CUR); 288 299 if (seekresult < pos) { 289 printf( "Error: Unable to seek past text data. " \290 "Text data could be missing\n") ;300 printf(B_TRANSLATE("Error: Unable to seek past text data. " \ 301 "Text data could be missing\n")); 291 302 return false; 292 303 } 293 304 if (seekresult > pos) { 294 printf( "Error: File position is beyond expected value\n");305 printf(B_TRANSLATE("Error: File position is beyond expected value\n")); 295 306 return false; 296 307 } 297 308 … … 300 311 TranslatorStyledTextStyleHeader stylheader; 301 312 read = file.Read(buffer, kstylsize); 302 313 if (read != static_cast<ssize_t>(kstylsize) && read != 0) { 303 printf( "Error: Unable to read entire style header\n");314 printf(B_TRANSLATE("Error: Unable to read entire style header\n")); 304 315 return false; 305 316 } 306 317 307 318 // If there is no STYL header (and no errors) 308 319 if (read != static_cast<ssize_t>(kstylsize)) { 309 printf("\nFile contains no Style Header (STYL section)\n"); 320 printf(B_TRANSLATE("\nFile contains no Style Header " 321 "(STYL section)\n")); 310 322 return false; 311 323 } 312 324 313 325 memcpy(&stylheader, buffer, kstylsize); 314 326 if (swap_data(B_UINT32_TYPE, &stylheader, kstylsize, 315 327 B_SWAP_BENDIAN_TO_HOST) != B_OK) { 316 printf("Error: Unable to swap byte order of style header\n"); 328 printf(B_TRANSLATE("Error: Unable to swap byte order of style " 329 "header\n")); 317 330 return false; 318 331 } 319 332 320 333 // Print Style Header (STYL) 321 printf( "\nStyle Header (STYL section):\n\n");334 printf(B_TRANSLATE("\nStyle Header (STYL section):\n\n")); 322 335 323 printf("magic number: 0x%.8lx ", stylheader.header.magic);324 336 if (stylheader.header.magic == 'STYL') 325 printf("(valid)\n"); 337 printf(B_TRANSLATE("magic number: 0x%.8lx (valid)\n"), 338 static_cast<unsigned long>(stylheader.header.magic)); 326 339 else 327 printf("(INVALID, should be 0x%.8lx)\n", 340 printf(B_TRANSLATE("magic number: 0x%.8lx (INVALID, should be " 341 "0x%.8lx)\n"), static_cast<unsigned long>(stylheader.header.magic), 328 342 static_cast<unsigned long>('STYL')); 329 343 330 printf("header size: %u ",331 static_cast<unsigned int>(stylheader.header.header_size));332 344 if (stylheader.header.header_size == kstylsize) 333 printf("(valid)\n"); 345 printf(B_TRANSLATE("header size: %u (valid)\n"), 346 static_cast<unsigned int>(stylheader.header.header_size)); 334 347 else 335 printf("(INVALID, should be %u)\n", 348 printf(B_TRANSLATE("header size: %u (INVALID, should be %u)\n"), 349 static_cast<unsigned int>(stylheader.header.header_size), 336 350 static_cast<unsigned int>(kstylsize)); 337 351 338 printf( "data size: %u\n",352 printf(B_TRANSLATE("data size: %u\n"), 339 353 static_cast<unsigned int>(stylheader.header.data_size)); 340 printf( "apply offset: %u (usually 0)\n",354 printf(B_TRANSLATE("apply offset: %u (usually 0)\n"), 341 355 static_cast<unsigned int>(stylheader.apply_offset)); 342 printf( "apply length: %u (usually the text data size)\n",356 printf(B_TRANSLATE("apply length: %u (usually the text data size)\n"), 343 357 static_cast<unsigned int>(stylheader.apply_length)); 344 358 345 359 // Check Styles 346 360 StylesHeader stylesheader; 347 361 read = file.Read(buffer, sizeof(StylesHeader)); 348 362 if (read != sizeof(StylesHeader)) { 349 printf( "Error: Unable to read Styles header\n");363 printf(B_TRANSLATE("Error: Unable to read Styles header\n")); 350 364 return false; 351 365 } 352 366 memcpy(&stylesheader, buffer, sizeof(StylesHeader)); 353 367 if (swap_data(B_UINT32_TYPE, &stylesheader, sizeof(StylesHeader), 354 368 B_SWAP_BENDIAN_TO_HOST) != B_OK) { 355 printf("Error: Unable to swap byte order of styles header\n"); 369 printf(B_TRANSLATE("Error: Unable to swap byte order of styles " 370 "header\n")); 356 371 return false; 357 372 } 358 373 359 374 // Print StylesHeader info 360 printf( "\nStyles Header (Ali! section):\n\n");375 printf(B_TRANSLATE("\nStyles Header (Ali! section):\n\n")); 361 376 362 printf("magic number: 0x%.8lx ",363 static_cast<unsigned long>(stylesheader.magic));364 377 if (stylesheader.magic == 'Ali!') 365 printf("(valid)\n"); 378 printf(B_TRANSLATE("magic number: 0x%.8lx (valid)\n"), 379 static_cast<unsigned long>(stylesheader.magic)); 366 380 else 367 printf("(INVALID, should be 0x%.8lx)\n", 381 printf(B_TRANSLATE("magic number: 0x%.8lx (INVALID, should be " 382 "0x%.8lx)\n"), static_cast<unsigned long>(stylesheader.magic), 368 383 static_cast<unsigned long>('Ali!')); 369 384 370 printf("version: 0x%.8lx ",371 static_cast<unsigned long>(stylesheader.version));372 385 if (stylesheader.version == 0) 373 printf("(valid)\n"); 386 printf(B_TRANSLATE("version: 0x%.8lx (valid)\n"), 387 static_cast<unsigned long>(stylesheader.version)); 374 388 else 375 printf("(INVALID, should be 0x%.8lx)\n", 0UL); 389 printf(B_TRANSLATE("version: 0x%.8lx (INVALID, should be 0x%.8lx)\n"), 390 static_cast<unsigned long>(stylesheader.version), 391 static_cast<unsigned long>(0UL)); 376 392 377 printf( "number of styles: %d\n",393 printf(B_TRANSLATE("number of styles: %d\n"), 378 394 static_cast<int>(stylesheader.count)); 379 395 380 396 // Check and Print out each style … … 382 398 Style style; 383 399 read = file.Read(&style, sizeof(Style)); 384 400 if (read != sizeof(Style)) { 385 printf( "Error: Unable to read style %d\n",401 printf(B_TRANSLATE("Error: Unable to read style %d\n"), 386 402 static_cast<int>(i + 1)); 387 403 return false; 388 404 } … … 401 417 if (argc == 2) { 402 418 BFile file(argv[1], B_READ_ONLY); 403 419 if (file.InitCheck() != B_OK) 404 printf( "Error opening %s\n", argv[1]);420 printf(B_TRANSLATE("Error opening %s\n"), argv[1]); 405 421 else { 406 printf("Be styled text information for: %s\n\n", argv[1]); 422 printf(B_TRANSLATE("Be styled text information for: %s\n\n"), 423 argv[1]); 407 424 if (PrintStylesAttribute(file) == false) { 408 printf( "Unable to read styles attribute, attempting to read" \409 " style information from file...\n\n");425 printf(B_TRANSLATE("Unable to read styles attribute, " \ 426 "attempting to read style information from file...\n\n")); 410 427 PrintStxtInfo(file); 411 428 } 412 429 } 413 430 } 414 431 else { 415 printf("stxtinfo - reports information about a Be styled text file\n"); 416 printf("\nUsage:\n"); 417 printf("stxtinfo filename.stxt\n"); 432 printf(B_TRANSLATE("stxtinfo - reports information about a Be styled " 433 "text file\n")); 434 printf(B_TRANSLATE("\nUsage:\n")); 435 printf(B_TRANSLATE("stxtinfo filename.stxt\n")); 418 436 } 419 437 420 438 printf("\n"); -
src/tools/translation/stxtinfo/Jamfile
1 1 SubDir HAIKU_TOP src tools translation stxtinfo ; 2 2 3 BinCommand stxtinfo : stxtinfo.cpp : be $(TARGET_LIBSUPC++);3 SetSubDirSupportedPlatformsBeOSCompatible ; 4 4 5 BinCommand stxtinfo : 6 stxtinfo.cpp 7 : be libbe.so $(HAIKU_LOCALE_LIBS) translation $(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++) ; 8 9 AddResources stxtinfo : stxtinfo.rdef ; 10 11 DoCatalogs stxtinfo : 12 x-vnd.Haiku-stxtinfo 13 : 14 stxtinfo.cpp 15 ; -
src/tools/translation/stxtinfo/stxtinfo.rdef
1 /* 2 * stxtinfo.rdef 3 */ 4 5 resource app_signature "application/x-vnd.Haiku-stxtinfo"; 6 7 resource app_version { 8 major = 1, 9 middle = 0, 10 minor = 0, 11 variety = 0, 12 internal = 0, 13 short_info = "stxtinfo displays text information about Be styled text (the format that StyledEdit uses).", 14 long_info = "Haiku stxtinfo is a command line tool for displaying text information about Be styled text (the format that StyledEdit uses). Written by Michael Wilber, OBOS Translation Kit Team, Copyright © 2003 OpenBeOS Project." 15 }; 16 17 resource app_flags B_SINGLE_LAUNCH;