diff --git a/headers/os/interface/Dragger.h b/headers/os/interface/Dragger.h index b87e88e2d1..623aa1172b 100644 --- a/headers/os/interface/Dragger.h +++ b/headers/os/interface/Dragger.h @@ -89,6 +89,7 @@ private: BDragger& operator=(const BDragger& other); + void _InitData(); void _AddToList(); void _RemoveFromList(); status_t _DetermineRelationship(); diff --git a/src/kits/interface/Dragger.cpp b/src/kits/interface/Dragger.cpp index 24ba8ea9e0..5712b4444a 100644 --- a/src/kits/interface/Dragger.cpp +++ b/src/kits/interface/Dragger.cpp @@ -18,7 +18,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -35,6 +37,15 @@ #include "ZombieReplicantView.h" +using BPrivate::gLocaleBackend; +using BPrivate::LocaleBackend; + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Dragger" + +#undef B_TRANSLATE +#define B_TRANSLATE(str) \ + gLocaleBackend->GetString(B_TRANSLATE_MARK(str), "Dragger") const uint32 kMsgDragStarted = 'Drgs'; @@ -114,8 +125,7 @@ BDragger::BDragger(BRect bounds, BView *target, uint32 rmask, uint32 flags) fPopUpIsCustom(false), fPopUp(NULL) { - fBitmap = new BBitmap(BRect(0.0f, 0.0f, 7.0f, 7.0f), B_CMAP8, false, false); - fBitmap->SetBits(kHandBitmap, fBitmap->BitsLength(), 0, B_CMAP8); + _InitData(); } @@ -132,8 +142,7 @@ BDragger::BDragger(BMessage *data) { data->FindInt32("_rel", (int32 *)&fRelation); - fBitmap = new BBitmap(BRect(0.0f, 0.0f, 7.0f, 7.0f), B_CMAP8, false, false); - fBitmap->SetBits(kHandBitmap, fBitmap->BitsLength(), 0, B_CMAP8); + _InitData(); BMessage popupMsg; if (data->FindMessage("_popup", &popupMsg) == B_OK) { @@ -292,10 +301,10 @@ BDragger::MessageReceived(BMessage *msg) if (fShelf != NULL) Window()->PostMessage(kDeleteReplicant, fTarget, NULL); else { - (new BAlert("??", - "Can't delete this replicant from its original " - "application. Life goes on.", - "OK", NULL, NULL, B_WIDTH_FROM_WIDEST, + (new BAlert(B_TRANSLATE("Warning"), + B_TRANSLATE("Can't delete this replicant from its original " + "application. Life goes on."), + B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_FROM_WIDEST, B_WARNING_ALERT))->Go(NULL); } break; @@ -615,6 +624,19 @@ BDragger::_UpdateShowAllDraggers(bool visible) } +void +BDragger::_InitData() +{ + fBitmap = new BBitmap(BRect(0.0f, 0.0f, 7.0f, 7.0f), B_CMAP8, false, false); + fBitmap->SetBits(kHandBitmap, fBitmap->BitsLength(), 0, B_CMAP8); + + // we need to translate some strings, and in order to do so, we need + // to use the LocaleBackend to reach liblocale.so + if (gLocaleBackend == NULL) + LocaleBackend::LoadBackend(); +} + + void BDragger::_AddToList() { @@ -722,12 +744,12 @@ BDragger::_BuildDefaultPopUp() if (name) msg->AddString("target", name); - char about[B_OS_NAME_LENGTH]; - snprintf(about, B_OS_NAME_LENGTH, "About %s" B_UTF8_ELLIPSIS, name); + BString about(B_TRANSLATE("About %app"B_UTF8_ELLIPSIS)); + about.ReplaceFirst("%app", name); - fPopUp->AddItem(new BMenuItem(about, msg)); + fPopUp->AddItem(new BMenuItem(about.String(), msg)); fPopUp->AddSeparatorItem(); - fPopUp->AddItem(new BMenuItem("Remove replicant", + fPopUp->AddItem(new BMenuItem(B_TRANSLATE("Remove replicant"), new BMessage(kDeleteReplicant))); } diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp index c5f6ecdd13..05d2fa1b23 100644 --- a/src/kits/interface/Menu.cpp +++ b/src/kits/interface/Menu.cpp @@ -17,12 +17,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -44,6 +46,17 @@ #define USE_CACHED_MENUWINDOW 1 +using BPrivate::gLocaleBackend; +using BPrivate::LocaleBackend; + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "Menu" + +#undef B_TRANSLATE +#define B_TRANSLATE(str) \ + gLocaleBackend->GetString(B_TRANSLATE_MARK(str), "Menu") + + using std::nothrow; using BPrivate::BMenuWindow; @@ -180,6 +193,7 @@ static property_info sPropList[] = { }; +// note: this is redefined to localized one in BMenu::_InitData const char* BPrivate::kEmptyMenuLabel = ""; @@ -1396,6 +1410,13 @@ void BMenu::_ReservedMenu6() {} void BMenu::_InitData(BMessage* archive) { + // we need to translate some strings, and in order to do so, we need + // to use the LocaleBackend to reach liblocale.so + if (gLocaleBackend == NULL) + LocaleBackend::LoadBackend(); + + BPrivate::kEmptyMenuLabel = B_TRANSLATE(""); + // TODO: Get _color, _fname, _fflt from the message, if present BFont font; font.SetFamilyAndStyle(sMenuInfo.f_family, sMenuInfo.f_style); diff --git a/src/kits/interface/PrintJob.cpp b/src/kits/interface/PrintJob.cpp index cf430cf5e0..ad761779aa 100644 --- a/src/kits/interface/PrintJob.cpp +++ b/src/kits/interface/PrintJob.cpp @@ -19,10 +19,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -34,6 +36,16 @@ #include #include +using BPrivate::gLocaleBackend; +using BPrivate::LocaleBackend; + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "PrintJob" + +#undef B_TRANSLATE +#define B_TRANSLATE(str) \ + gLocaleBackend->GetString(B_TRANSLATE_MARK(str), "PrintJob") + /*! Summary of spool file: @@ -92,7 +104,7 @@ struct _page_header_ { static void ShowError(const char* message) { - BAlert* alert = new BAlert("Error", message, "OK"); + BAlert* alert = new BAlert(B_TRANSLATE("Error"), message, B_TRANSLATE("OK")); alert->Go(); } @@ -158,6 +170,11 @@ BPrintJob::BPrintJob(const char* jobName) fCurrentPageHeader = new _page_header_; if (fCurrentPageHeader != NULL) memset(fCurrentPageHeader, 0, sizeof(_page_header_)); + + // we need to translate some strings, and in order to do so, we need + // to use the LocaleBackend to reach liblocale.so + if (gLocaleBackend == NULL) + LocaleBackend::LoadBackend(); } @@ -282,7 +299,7 @@ BPrintJob::CommitJob() return; if (fSpoolFileHeader.page_count == 0) { - ShowError("No Pages to print!"); + ShowError(B_TRANSLATE("No Pages to print!")); CancelJob(); return; } @@ -843,7 +860,7 @@ PrintServerMessenger::MessengerThread(void* data) BMessenger printServer; if (messenger->GetPrintServerMessenger(printServer) != B_OK) { - ShowError("Print Server is not responding."); + ShowError(B_TRANSLATE("Print Server is not responding.")); messenger->SetResult(NULL); return B_ERROR; } diff --git a/src/kits/interface/ZombieReplicantView.cpp b/src/kits/interface/ZombieReplicantView.cpp index 4b15986d83..9ff0303651 100644 --- a/src/kits/interface/ZombieReplicantView.cpp +++ b/src/kits/interface/ZombieReplicantView.cpp @@ -7,8 +7,11 @@ */ #include +#include +#include #include #include +#include #include "ZombieReplicantView.h" @@ -17,6 +20,15 @@ #include #include +using BPrivate::gLocaleBackend; +using BPrivate::LocaleBackend; + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "ZombieReplicantView" + +#undef B_TRANSLATE +#define B_TRANSLATE(str) \ + gLocaleBackend->GetString(B_TRANSLATE_MARK(str), "ZombieReplicantView") _BZombieReplicantView_::_BZombieReplicantView_(BRect frame, status_t error) @@ -28,6 +40,11 @@ _BZombieReplicantView_::_BZombieReplicantView_(BRect frame, status_t error) font.SetSize(9.0f); // TODO SetFont(&font); SetViewColor(kZombieColor); + + // we need to translate some strings, and in order to do so, we need + // to use the LocaleBackend to reach liblocale.so + if (gLocaleBackend == NULL) + LocaleBackend::LoadBackend(); } @@ -43,23 +60,23 @@ _BZombieReplicantView_::MessageReceived(BMessage* msg) case B_ABOUT_REQUESTED: { const char* addOn = NULL; - char error[1024]; + BString error; if (fArchive->FindString("add_on", &addOn) == B_OK) { char description[B_MIME_TYPE_LENGTH] = ""; BMimeType type(addOn); type.GetShortDescription(description); - snprintf(error, sizeof(error), - "Cannot create the replicant for \"%s\". (%s)", - description, strerror(fError)); - } else { - snprintf(error, sizeof(error), - "Cannot locate the application for the replicant. " - "No application signature supplied. (%s)", strerror(fError)); - } - + error = B_TRANSLATE("Cannot create the replicant for " + "\"%description\".\n%error"); + error.ReplaceFirst("%description", description); + } else + error = B_TRANSLATE("Cannot locate the application for the " + "replicant. No application signature supplied.\n%error)"); + + error.ReplaceFirst("%error", strerror(fError)); - BAlert* alert = new (std::nothrow) BAlert("Error", error, "OK", NULL, NULL, - B_WIDTH_AS_USUAL, B_STOP_ALERT); + BAlert* alert = new (std::nothrow) BAlert(B_TRANSLATE("Error"), + error.String(), B_TRANSLATE("OK"), NULL, NULL, + B_WIDTH_AS_USUAL, B_STOP_ALERT); if (alert != NULL) alert->Go(); diff --git a/src/kits/locale/Jamfile b/src/kits/locale/Jamfile index c99ff82b9a..897b16d6d3 100644 --- a/src/kits/locale/Jamfile +++ b/src/kits/locale/Jamfile @@ -68,13 +68,21 @@ SEARCH on [ FGristFiles AboutWindow.cpp ] += [ FDirName $(HAIKU_TOP) src kits sh SEARCH on [ FGristFiles ColorControl.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; SEARCH on [ FGristFiles StringForSize.cpp ] += [ FDirName $(HAIKU_TOP) src kits shared ] ; SEARCH on [ FGristFiles TextView.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; - +SEARCH on [ FGristFiles Dragger.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; +SEARCH on [ FGristFiles Menu.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; +SEARCH on [ FGristFiles PrintJob.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; +SEARCH on [ FGristFiles ZombieReplicantView.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; + DoCatalogs liblocale.so : system : AboutMenuItem.cpp AboutWindow.cpp ColorControl.cpp + Dragger.cpp + Menu.cpp + PrintJob.cpp StringForSize.cpp TextView.cpp + ZombieReplicantView.cpp ;