Ticket #7167: stxtinfo-localization.patch

File stxtinfo-localization.patch, 17.0 KB (added by Karvjorm, 13 years ago)

A stxtinfo localization patch

  • src/tools/translation/stxtinfo/stxtinfo.cpp

     
    4848#include <stdlib.h>
    4949#include <string.h>
    5050#include <ByteOrder.h>
     51#include <Catalog.h>
    5152#include <File.h>
    5253#include <TranslatorFormats.h>
    5354#include <Font.h>
     
    5556#include <fs_attr.h>
    5657    // for attr_info
    5758
     59#undef B_TRANSLATE_CONTEXT
     60#define B_TRANSLATE_CONTEXT "stxtinfo"
     61
    5862#define max(x,y) ((x > y) ? x : y)
    5963#define DATA_BUFFER_SIZE 64
    6064
     
    8791    style.face = B_BENDIAN_TO_HOST_INT16(style.face);
    8892    style.reserved = B_BENDIAN_TO_HOST_INT16(style.reserved);           
    8993           
    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"),
    97101        static_cast<unsigned int>(style.face));
    98     printf("RGBA: (%u, %u, %u, %u)\n",
     102    printf(B_TRANSLATE("RGBA: (%u, %u, %u, %u)\n"),
    99103        static_cast<unsigned int>(style.red),
    100104        static_cast<unsigned int>(style.blue),
    101105        static_cast<unsigned int>(style.green),
    102106        static_cast<unsigned int>(style.alpha));
    103         printf("reserved: %u (should be 0)\n",
     107        printf(B_TRANSLATE("reserved: %u (should be 0)\n"),
    104108        static_cast<unsigned int>(style.reserved));
    105109}
    106110
     
    113117    if (file.GetAttrInfo(kAttrName, &info) != B_OK)
    114118        return false;
    115119    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"));
    117121        return false;
    118122    }
    119123    if (info.size < 160) {
    120         printf("Error: styles attribute is missing information\n");
     124        printf(B_TRANSLATE("Error: styles attribute is missing information\n"));
    121125        return false;
    122126    }
    123127
    124128    uint8 *pflatRunArray = new uint8[info.size];
    125129    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"));
    127132        return false;
    128133    }
    129134   
    130135    ssize_t amtread = file.ReadAttr(kAttrName, B_RAW_TYPE, 0,
    131136        pflatRunArray, info.size);
    132137    if (amtread != info.size) {
    133         printf("Error: Unable to read styles attribute\n");
     138        printf(B_TRANSLATE("Error: Unable to read styles attribute\n"));
    134139        return false;
    135140    }
    136141               
     
    139144    memcpy(&stylesheader, pflatRunArray, sizeof(StylesHeader));
    140145    if (swap_data(B_UINT32_TYPE, &stylesheader, sizeof(StylesHeader),
    141146        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"));
    143149        return false;
    144150    }
    145151       
    146152    // Print StylesHeader info
    147     printf("\"styles\" attribute data:\n\n");
     153    printf(B_TRANSLATE("\"styles\" attribute data:\n\n"));
    148154   
    149     printf("magic number: 0x%.8lx ",
    150         static_cast<unsigned long>(stylesheader.magic));
    151155    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));
    153158    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),
    155161            static_cast<unsigned long>('Ali!'));
    156162       
    157     printf("version: 0x%.8lx ",
    158         static_cast<unsigned long>(stylesheader.version));
    159163    if (stylesheader.version == 0)
    160         printf("(valid)\n");
     164        printf(B_TRANSLATE("version: 0x%.8lx (valid)\n"),
     165            static_cast<unsigned long>(stylesheader.version));
    161166    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);
    163169           
    164     printf("number of styles: %d\n",
     170    printf(B_TRANSLATE("number of styles: %d\n"),
    165171        static_cast<int>(stylesheader.count));
    166172       
    167173    // Check and Print out each style
     
    189195    status_t nread = 0;
    190196    nread = file.Read(buffer, kstxtsize);
    191197    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"));
    193199        return false;
    194200    }
    195201    TranslatorStyledTextStreamHeader stxtheader;
    196202    memcpy(&stxtheader, buffer, kstxtsize);
    197203    if (swap_data(B_UINT32_TYPE, &stxtheader, kstxtsize,
    198204        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"));
    200207        return false;
    201208    }
    202209   
    203210    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"));
    205213        return false;
    206214    }
    207215       
    208216    // Print Stream Header (STXT)
    209     printf("Stream Header (STXT section):\n\n");
     217    printf(B_TRANSLATE("Stream Header (STXT section):\n\n"));
    210218       
    211     printf("magic number: 0x%.8lx ", stxtheader.header.magic);
    212219    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));
    214222    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),
    216225            static_cast<unsigned long>(B_STYLED_TEXT_FORMAT));
    217226               
    218     printf("header size: %u ",
     227    if (stxtheader.header.header_size == kstxtsize)
     228        printf(B_TRANSLATE("header size: %u (valid)\n"),
    219229        static_cast<unsigned int>(stxtheader.header.header_size));
    220     if (stxtheader.header.header_size == kstxtsize)
    221         printf("(valid)\n");
    222230    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),
    224233            static_cast<unsigned int>(kstxtsize));
    225234               
    226     printf("data size: %u ",
    227         static_cast<unsigned int>(stxtheader.header.data_size));
    228235    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));
    230238    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));
    232241           
    233     printf("version: %d ",
    234         static_cast<int>(stxtheader.version));
    235242    if (stxtheader.version == 100)
    236         printf("(valid)\n");
     243        printf(B_TRANSLATE("version: %d (valid)\n"),
     244            static_cast<int>(stxtheader.version));
    237245        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));
    239248
    240249   
    241250    // Check the TEXT header
    242251    TranslatorStyledTextTextHeader txtheader;
    243252    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"));
    245254        return false;
    246255    }
    247256    memcpy(&txtheader, buffer, ktxtsize);
    248257    if (swap_data(B_UINT32_TYPE, &txtheader, ktxtsize,
    249258        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"));
    251261        return false;
    252262    }
    253263           
    254264    // Print Text Header (TEXT)
    255     printf("\nText Header (TEXT section):\n\n");
     265    printf(B_TRANSLATE("\nText Header (TEXT section):\n\n"));
    256266       
    257     printf("magic number: 0x%.8lx ", txtheader.header.magic);
    258267    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));
    260270    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),
    262273            static_cast<unsigned long>('TEXT'));
    263274               
    264     printf("header size: %u ",
    265         static_cast<unsigned int>(txtheader.header.header_size));
    266275    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));
    268278    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),
    270281            static_cast<unsigned int>(ktxtsize));
    271282               
    272     printf("data size (bytes of text): %u\n",
     283    printf(B_TRANSLATE("data size (bytes of text): %u\n"),
    273284        static_cast<unsigned int>(txtheader.header.data_size));
    274285           
    275     printf("character set: %d ",
    276         static_cast<int>(txtheader.charset));
    277286    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));
    279289    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);
    281292           
    282293    // Skip the text data
    283294    off_t seekresult, pos;
     
    286297        txtheader.header.data_size;
    287298    seekresult = file.Seek(txtheader.header.data_size, SEEK_CUR);
    288299    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"));
    291302        return false;
    292303    }
    293304    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"));
    295306        return false;
    296307    }
    297308
     
    300311    TranslatorStyledTextStyleHeader stylheader;
    301312    read = file.Read(buffer, kstylsize);
    302313    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"));
    304315        return false;
    305316    }
    306317   
    307318    // If there is no STYL header (and no errors)
    308319    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"));
    310322        return false;
    311323    }
    312324           
    313325    memcpy(&stylheader, buffer, kstylsize);
    314326    if (swap_data(B_UINT32_TYPE, &stylheader, kstylsize,
    315327        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"));
    317330        return false;
    318331    }
    319332       
    320333    // Print Style Header (STYL)
    321     printf("\nStyle Header (STYL section):\n\n");
     334    printf(B_TRANSLATE("\nStyle Header (STYL section):\n\n"));
    322335   
    323     printf("magic number: 0x%.8lx ", stylheader.header.magic);
    324336    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));
    326339    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),
    328342            static_cast<unsigned long>('STYL'));
    329343               
    330     printf("header size: %u ",
    331         static_cast<unsigned int>(stylheader.header.header_size));
    332344    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));
    334347    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),
    336350            static_cast<unsigned int>(kstylsize));
    337351               
    338     printf("data size: %u\n",
     352    printf(B_TRANSLATE("data size: %u\n"),
    339353        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"),
    341355        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"),
    343357        static_cast<unsigned int>(stylheader.apply_length));
    344358           
    345359    // Check Styles
    346360    StylesHeader stylesheader;
    347361    read = file.Read(buffer, sizeof(StylesHeader));
    348362    if (read != sizeof(StylesHeader)) {
    349         printf("Error: Unable to read Styles header\n");
     363        printf(B_TRANSLATE("Error: Unable to read Styles header\n"));
    350364        return false;
    351365    }
    352366    memcpy(&stylesheader, buffer, sizeof(StylesHeader));
    353367    if (swap_data(B_UINT32_TYPE, &stylesheader, sizeof(StylesHeader),
    354368        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"));
    356371        return false;
    357372    }
    358373       
    359374    // Print StylesHeader info
    360     printf("\nStyles Header (Ali! section):\n\n");
     375    printf(B_TRANSLATE("\nStyles Header (Ali! section):\n\n"));
    361376   
    362     printf("magic number: 0x%.8lx ",
    363         static_cast<unsigned long>(stylesheader.magic));
    364377    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));
    366380    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),
    368383            static_cast<unsigned long>('Ali!'));
    369384       
    370     printf("version: 0x%.8lx ",
    371         static_cast<unsigned long>(stylesheader.version));
    372385    if (stylesheader.version == 0)
    373         printf("(valid)\n");
     386        printf(B_TRANSLATE("version: 0x%.8lx (valid)\n"),
     387            static_cast<unsigned long>(stylesheader.version));
    374388    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));
    376392           
    377     printf("number of styles: %d\n",
     393    printf(B_TRANSLATE("number of styles: %d\n"),
    378394        static_cast<int>(stylesheader.count));
    379395       
    380396    // Check and Print out each style
     
    382398        Style style;
    383399        read = file.Read(&style, sizeof(Style));
    384400        if (read != sizeof(Style)) {
    385             printf("Error: Unable to read style %d\n",
     401            printf(B_TRANSLATE("Error: Unable to read style %d\n"),
    386402                static_cast<int>(i + 1));
    387403            return false;
    388404        }           
     
    401417    if (argc == 2) {
    402418        BFile file(argv[1], B_READ_ONLY);
    403419        if (file.InitCheck() != B_OK)
    404             printf("Error opening %s\n", argv[1]);
     420            printf(B_TRANSLATE("Error opening %s\n"), argv[1]);
    405421        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]);
    407424            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"));
    410427                PrintStxtInfo(file);
    411428            }
    412429        }
    413430    }
    414431    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"));   
    418436    }
    419437   
    420438    printf("\n");
  • src/tools/translation/stxtinfo/Jamfile

     
    11SubDir HAIKU_TOP src tools translation stxtinfo ;
    22
    3 BinCommand stxtinfo : stxtinfo.cpp : be $(TARGET_LIBSUPC++) ;
     3SetSubDirSupportedPlatformsBeOSCompatible ;
    44
     5BinCommand stxtinfo :
     6    stxtinfo.cpp
     7    : be libbe.so $(HAIKU_LOCALE_LIBS) translation $(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++) ;
     8
     9AddResources stxtinfo : stxtinfo.rdef ;
     10
     11DoCatalogs stxtinfo :
     12    x-vnd.Haiku-stxtinfo
     13    :
     14    stxtinfo.cpp
     15;
  • src/tools/translation/stxtinfo/stxtinfo.rdef

     
     1/*
     2 * stxtinfo.rdef
     3 */
     4
     5resource app_signature "application/x-vnd.Haiku-stxtinfo";
     6
     7resource 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
     17resource app_flags B_SINGLE_LAUNCH;