localization.cpp

00001 #include <gui/GUI.h>
00002 #include <os/OS.h>
00003 
00004 using namespace SkyGI;
00005 
00006 class MyLocalization : public View
00007 {
00008 public:
00009         MyLocalization(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags);
00010         TextView *pTextView;
00011 };
00012         
00013 MyLocalization::MyLocalization(Window *pParent, const Rect &rFrame, unsigned int nWindowLayoutFlags) : View(pParent, rFrame, nWindowLayoutFlags)
00014 {
00015         Catalog *pCatalog;
00016 
00017         pTextView = new TextView(this, Rect(0,0,0,0), WINDOW_LAYOUT_SAME_SIZE);
00018 
00019         // The Application instance already loaded the primary catalog for the current system set language
00020         // using the directory this application resits in from the subfolder resource/translation
00021         // Get two strings and display them using LocalizedString class
00022         pTextView->Append(String("System set local string 0: ") + LocalizedString(0), true);
00023         pTextView->Append(String("System set local string 1: ") + LocalizedString(1), true);
00024         pTextView->Append(String("System set local string 100: ") + LocalizedString(100), true);
00025 
00026         // Now load the english catalog by manually constructing the path to it
00027         pCatalog = new Catalog();
00028         pCatalog->LoadFromDirectory(Application::GetInstance()->GetApplicationDirectory() + "resource/translation", "en");
00029         pTextView->Append(String("en string 0: ") + LocalizedString(0, pCatalog), true);
00030         pTextView->Append(String("en string 1: ") + LocalizedString(1, pCatalog), true);
00031         pTextView->Append(String("en string 100: ") + LocalizedString(100, pCatalog), true);
00032 
00033         // Apply the english catalog as default one so we can quickly access it with LocalizedString
00034         Application::GetInstance()->SetCatalog(pCatalog);
00035         pTextView->Append(String("Current local string 0: ") + LocalizedString(0), true);
00036         pTextView->Append(String("Current local string 1: ") + LocalizedString(1), true);
00037         pTextView->Append(String("Current local string 100: ") + LocalizedString(100), true);
00038 
00039         // Now load the german catalog 
00040         pCatalog->LoadFromDirectory(Application::GetInstance()->GetApplicationDirectory() + "resource/translation", "de");
00041         pTextView->Append(String("de string 0: ") + LocalizedString(0, pCatalog), true);
00042         pTextView->Append(String("de string 1: ") + LocalizedString(1, pCatalog), true);
00043         pTextView->Append(String("de string 100: ") + LocalizedString(100, pCatalog), true);
00044 
00045         // Apply the german catalog as default one so we can quickly access it with LocalizedString
00046         Application::GetInstance()->SetCatalog(pCatalog);
00047         pTextView->Append(String("Current local string 0: ") + LocalizedString(0), true);
00048         pTextView->Append(String("Current local string 1: ") + LocalizedString(1), true);
00049         pTextView->Append(String("Current local string 100: ") + LocalizedString(100), true);
00050 
00051         // Finally load and apply the english catalog again
00052         pCatalog->LoadFromDirectory(Application::GetInstance()->GetApplicationDirectory() + "resource/translation", "en");
00053         Application::GetInstance()->SetCatalog(pCatalog);
00054 }
00055 
00056 void LocalizationTest()
00057 {
00058         Rect r(Point(100, 100), Point(400, 440));
00059 
00060         ApplicationWindow* pApplicationWindow = new ApplicationWindow(r, "Localization", WINDOW_LAYOUT_NOTHING, APPLICATION_WINDOW_NO_VIEW);
00061         
00062         pApplicationWindow->GetTitleWindow()->SetFlags( (TitleWindowFlags)(pApplicationWindow->GetTitleWindow()->GetFlags() ));
00063         pApplicationWindow->AttachView(new MyLocalization(pApplicationWindow, pApplicationWindow->GetClientRect(), WINDOW_LAYOUT_NOTHING));
00064         pApplicationWindow->Show();
00065 }
00066 

Generated on Thu Dec 13 18:13:10 2007 for SkyGI by  doxygen 1.5.1-p1