void initFactories() { static bool initialized = false; if(!initialized) { new INTERN_ButtonFactory(); new INTERN_DesktopFactory(); new INTERN_DocumentFactory(); new INTERN_FilledRectangleFactory(); new INTERN_GradientFactory(); new INTERN_ImageFactory(); new INTERN_PanelFactory(); new INTERN_ParagraphFactory(); new INTERN_ScrollBarFactory(); new INTERN_ScrollViewFactory(); new INTERN_SwitchComponentFactory(); new INTERN_TableLayoutFactory(); new INTERN_TooltipManagerFactory(); new INTERN_WindowFactory(); new ImportFactory(); dictionaryGUIManager.set_charset("UTF-8"); dictionaryGUIManager.add_directory("locale/gui"); initialized = true; } }
void PingusMain::apply_args() { // FIXME: merge cmd_options with stuff read from config file here auto& options = cmd_options; // Mode toggles if (options.list_languages.is_set() && options.list_languages.get()) { // language listing only works after the data path has been set std::cout << "Available languages are:" << std::endl; std::cout << "========================" << std::endl; std::set<tinygettext::Language> lst = dictionary_manager.get_languages(); for (std::set<tinygettext::Language>::iterator i = lst.begin(); i != lst.end(); ++i) std::cout << i->get_name() << " (" << i->str() << ")" << std::endl; std::cout << "\nLanguages can be used via:\n\n pingus --language de\n" << std::endl; exit(EXIT_SUCCESS); } if (options.software_cursor.is_set()) globals::software_cursor = options.software_cursor.get(); // Sound if (options.disable_music.is_set()) globals::music_enabled = !options.disable_music.get(); if (options.disable_sound.is_set()) globals::sound_enabled = !options.disable_sound.get(); // Misc if (options.language.is_set()) dictionary_manager.set_language(tinygettext::Language::from_name(options.language.get())); if (options.auto_scrolling.is_set()) globals::auto_scrolling = options.auto_scrolling.get(); if (options.drag_drop_scrolling.is_set()) globals::drag_drop_scrolling = options.drag_drop_scrolling.get(); if (options.developer_mode.is_set()) globals::developer_mode = options.developer_mode.get(); if (options.speed.is_set()) globals::game_speed = options.speed.get(); if (options.desiredfps.is_set()) globals::desired_fps = options.desiredfps.get(); if (options.tile_size.is_set()) globals::tile_size = options.tile_size.get(); }
// Get all filenames and directories void PingusMain::init_path_finder() { if (cmd_options.userdir.is_set()) System::set_userdir(cmd_options.userdir.get()); System::init_directories(); if (cmd_options.datadir.is_set()) { g_path_manager.set_path(cmd_options.datadir.get()); } else { // do magic to guess the datadir #if defined(__APPLE__) char resource_path[PATH_MAX]; CFURLRef ref = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); if (!ref || !CFURLGetFileSystemRepresentation(ref, true, (UInt8*)resource_path, PATH_MAX)) { std::cout << "Error: Couldn't get Resources path.\n" << std::endl; exit(EXIT_FAILURE); } CFRelease(ref); g_path_manager.set_path("data"); #else g_path_manager.set_path("data"); // assume game is run from source dir #endif } // Language is automatically picked from env variable //dictionary_manager.set_language(tinygettext::Language::from_env("it_IT.utf8")); // maybe overwritten by file ~/.pingus/config dictionary_manager.add_directory(g_path_manager.complete("po/")); }
void PingusMain::print_greeting_message() { std::string greeting = "Welcome to Pingus 0.7.6"/*VERSION*/; greeting += "!"; std::cout << greeting << std::endl; for (unsigned int i = 0; i < greeting.length(); ++i) std::cout.put('='); std::cout << std::endl; std::cout << "userdir: " << System::get_userdir() << std::endl; std::cout << "datadir: " << g_path_manager.get_path() << std::endl; std::cout << "language: " << dictionary_manager.get_language().get_name() << " (" << dictionary_manager.get_language().str() << ")" << std::endl; if (globals::sound_enabled) std::cout << "sound support: enabled" << std::endl; else std::cout << "sound support: disabled" << std::endl; if (globals::music_enabled) std::cout << "music support: enabled" << std::endl; else std::cout << "music support: disabled" << std::endl; std::cout << "fullscreen: "; if (cmd_options.fullscreen.is_set() && cmd_options.fullscreen.get()) { std::cout << cmd_options.fullscreen_resolution.get().width << "x" << cmd_options.fullscreen_resolution.get().height << std::endl; } else { std::cout << "disabled" << std::endl; } std::cout << std::endl; }
/** * @brief Loads a localization file * @param[in] language */ void I18N_SetLanguage(const char *language) { // TODO: check if there is a localization file available for the selected language dictionary.set_language(tinygettext::Language::from_env(std::string(language))); dictionary_mod.set_language(tinygettext::Language::from_env(std::string(language))); Com_Printf("Language set to %s\n", dictionary.get_language().get_name().c_str()); Com_sprintf(cl_lang_last, sizeof(cl_lang_last), "%s", language); if (!Q_stricmp(cl_lang->string, "en")) { doTranslate = qfalse; } else { doTranslate = qtrue; } strings.clear(); }
void ConfigManager::set_language(const tinygettext::Language& v) { log_info("%1%", v.str()); if (v != get_language()) { dictionary_manager.set_language(v); on_language_change(v); } m_opts.language.set(v.str()); }
/** * @brief Attempts to detect the system language unless cl_lang was already set. * Then loads the PO file containing translated strings. */ void I18N_Init(void) { FL_Locale *locale; std::set<tinygettext::Language> languages; std::set<tinygettext::Language> languages_mod; cl_lang = Cvar_Get("cl_lang", "en", CVAR_ARCHIVE | CVAR_LATCH); cl_langDebug = Cvar_Get("cl_langDebug", "0", CVAR_ARCHIVE); tinygettext::Log::set_log_error_callback(&Tinygettext_Error); tinygettext::Log::set_log_info_callback(&Tinygettext_Info); tinygettext::Log::set_log_warning_callback(&Tinygettext_Warning); FL_FindLocale(&locale); // Do not change the language if it is already set if (!cl_lang->string[0]) { // locale->country is also supported for 'en_US' format if (locale->lang && locale->lang[0]) { Cvar_Set("cl_lang", va("%s", locale->lang)); } else { // Language detection failed. Fallback to English Cvar_Set("cl_lang", "en"); } } dictionary.set_filesystem(std::auto_ptr<tinygettext::FileSystem>(new QFileSystem)); dictionary_mod.set_filesystem(std::auto_ptr<tinygettext::FileSystem>(new QFileSystem)); dictionary.add_directory("locale/client"); dictionary_mod.add_directory("locale/mod"); languages = dictionary.get_languages(); Com_Printf("Available client translations:"); for (std::set<tinygettext::Language>::iterator p = languages.begin(); p != languages.end(); p++) { Com_Printf(" %s", p->get_name().c_str()); } Com_Printf("\n"); languages_mod = dictionary_mod.get_languages(); Com_Printf("Available mod translations:"); for (std::set<tinygettext::Language>::iterator p = languages_mod.begin(); p != languages_mod.end(); p++) { Com_Printf(" %s", p->get_name().c_str()); } Com_Printf("\n"); I18N_SetLanguage(cl_lang->string); FL_FreeLocale(&locale); }
OptionMenu::OptionMenu() : m_background("core/menu/wood"), m_blackboard("core/menu/blackboard"), ok_button(), x_pos(), y_pos(), options(), fullscreen_box(), software_cursor_box(), autoscroll_box(), dragdrop_scroll_box(), mousegrab_box(), printfps_box(), master_volume_box(), sound_volume_box(), music_volume_box(), //defaults_label(), //defaults_box(), connections(), m_language(), m_language_map() { gui_manager->add(ok_button = new OptionMenuCloseButton(this, Display::get_width()/2 + 245, Display::get_height()/2 + 150)); x_pos = 0; y_pos = 0; ChoiceBox* resolution_box = new ChoiceBox(Rect()); { std::vector<SDL_DisplayMode> resolutions = Display::get_fullscreen_video_modes(); Size fullscreen = config_manager.get_fullscreen_resolution(); int choice = static_cast<int>(resolutions.size()) - 1; for (auto it = resolutions.begin(); it != resolutions.end(); ++it) { // add resolution to the box std::ostringstream ostr; ostr << it->w << "x" << it->h << "@" << it->refresh_rate; resolution_box->add_choice(ostr.str()); // FIXME: ignoring refresh_rate if (fullscreen.width == it->w && fullscreen.height == it->h) { choice = static_cast<int>(it - resolutions.begin()); } } resolution_box->set_current_choice(choice); } ChoiceBox* renderer_box = new ChoiceBox(Rect()); renderer_box->add_choice("sdl"); renderer_box->add_choice("delta"); renderer_box->add_choice("opengl"); switch(config_manager.get_renderer()) { case SDL_FRAMEBUFFER: renderer_box->set_current_choice(0); break; case DELTA_FRAMEBUFFER: renderer_box->set_current_choice(1); break; case OPENGL_FRAMEBUFFER: renderer_box->set_current_choice(2); break; default: assert(!"unknown renderer type"); } m_language = dictionary_manager.get_language(); ChoiceBox* language_box = new ChoiceBox(Rect()); { std::set<tinygettext::Language> languages = dictionary_manager.get_languages(); // English is the default language, thus it's not in the list of // languages returned by tinygettext and we have to add it manually languages.insert(tinygettext::Language::from_name("en")); std::vector<tinygettext::Language> langs(languages.begin(), languages.end()); std::sort(langs.begin(), langs.end(), LanguageSorter()); for (auto i = langs.begin(); i != langs.end(); ++i) { m_language_map[i->get_name()] = *i; language_box->add_choice(i->get_name()); if (m_language == *i) { language_box->set_current_choice(static_cast<int>(i - langs.begin())); } } } ChoiceBox* scroll_box = new ChoiceBox(Rect()); scroll_box->add_choice("Drag&Drop"); scroll_box->add_choice("Rubberband"); software_cursor_box = new CheckBox(Rect()); fullscreen_box = new CheckBox(Rect()); autoscroll_box = new CheckBox(Rect()); dragdrop_scroll_box = new CheckBox(Rect()); mousegrab_box = new CheckBox(Rect()); printfps_box = new CheckBox(Rect()); master_volume_box = new SliderBox(Rect(), 25); sound_volume_box = new SliderBox(Rect(), 25); music_volume_box = new SliderBox(Rect(), 25); master_volume_box->set_value(config_manager.get_master_volume()); sound_volume_box->set_value(config_manager.get_sound_volume()); music_volume_box->set_value(config_manager.get_music_volume()); C(software_cursor_box->on_change.connect(std::bind(&OptionMenu::on_software_cursor_change, this, std::placeholders::_1))); C(fullscreen_box->on_change.connect(std::bind(&OptionMenu::on_fullscreen_change, this, std::placeholders::_1))); C(autoscroll_box->on_change.connect(std::bind(&OptionMenu::on_autoscroll_change, this, std::placeholders::_1))); C(dragdrop_scroll_box->on_change.connect(std::bind(&OptionMenu::on_drag_drop_scrolling_change, this, std::placeholders::_1))); C(mousegrab_box->on_change.connect(std::bind(&OptionMenu::on_mousegrab_change, this, std::placeholders::_1))); C(printfps_box->on_change.connect(std::bind(&OptionMenu::on_printfps_change, this, std::placeholders::_1))); C(master_volume_box->on_change.connect(std::bind(&OptionMenu::on_master_volume_change, this, std::placeholders::_1))); C(sound_volume_box->on_change.connect(std::bind(&OptionMenu::on_sound_volume_change, this, std::placeholders::_1))); C(music_volume_box->on_change.connect(std::bind(&OptionMenu::on_music_volume_change, this, std::placeholders::_1))); C(language_box->on_change.connect(std::bind(&OptionMenu::on_language_change, this, std::placeholders::_1))); C(resolution_box->on_change.connect(std::bind(&OptionMenu::on_resolution_change, this, std::placeholders::_1))); C(renderer_box->on_change.connect(std::bind(&OptionMenu::on_renderer_change, this, std::placeholders::_1))); x_pos = 0; y_pos = 0; add_item(_("Fullscreen"), fullscreen_box); add_item(_("Mouse Grab"), mousegrab_box); y_pos += 1; add_item(_("Software Cursor"), software_cursor_box); add_item(_("Autoscrolling"), autoscroll_box); add_item(_("Drag&Drop Scrolling"), dragdrop_scroll_box); y_pos += 1; add_item(_("Print FPS"), printfps_box); x_pos = 1; y_pos = 0; add_item(_("Resolution:"), resolution_box); add_item(_("Renderer:"), renderer_box); y_pos += 1; add_item(_("Language:"), language_box); y_pos += 1; add_item(_("Master Volume:"), master_volume_box); add_item(_("Sound Volume:"), sound_volume_box); add_item(_("Music Volume:"), music_volume_box); // Connect with ConfigManager mousegrab_box->set_state(config_manager.get_mouse_grab(), false); C(config_manager.on_mouse_grab_change.connect(std::bind(&CheckBox::set_state, mousegrab_box, std::placeholders::_1, false))); printfps_box->set_state(config_manager.get_print_fps(), false); C(config_manager.on_print_fps_change.connect(std::bind(&CheckBox::set_state, printfps_box, std::placeholders::_1, false))); fullscreen_box->set_state(config_manager.get_fullscreen(), false); C(config_manager.on_fullscreen_change.connect(std::bind(&CheckBox::set_state, fullscreen_box, std::placeholders::_1, false))); software_cursor_box->set_state(config_manager.get_software_cursor(), false); C(config_manager.on_software_cursor_change.connect(std::bind(&CheckBox::set_state, software_cursor_box, std::placeholders::_1, false))); autoscroll_box->set_state(config_manager.get_auto_scrolling(), false); C(config_manager.on_auto_scrolling_change.connect(std::bind(&CheckBox::set_state, autoscroll_box, std::placeholders::_1, false))); dragdrop_scroll_box->set_state(config_manager.get_drag_drop_scrolling(), false); C(config_manager.on_drag_drop_scrolling_change.connect(std::bind(&CheckBox::set_state, dragdrop_scroll_box, std::placeholders::_1, false))); /* defaults_label = new Label(_("Reset to Defaults:"), Rect(Vector2i(Display::get_width()/2 - 100, Display::get_height()/2 + 160), Size(170, 32))); gui_manager->add(defaults_label); defaults_box = new CheckBox(Rect(Vector2i(Display::get_width()/2 - 100 + 170, Display::get_height()/2 + 160), Size(32, 32))); gui_manager->add(defaults_box); */ }
tinygettext::Language ConfigManager::get_language() const { return dictionary_manager.get_language(); }
static inline const char* N_(const char* id, const char* id2, int num) { return dictionary_manager.get_dictionary().translate(id, id2, num).c_str(); }
static inline const char* _(const char* message) { return dictionary_manager.get_dictionary().translate(message); }
static inline std::string _(const std::string& message) { return dictionary_manager.get_dictionary().translate(message); }
int PingusMain::run(int argc, char** argv) { g_logger.set_log_level(Logger::kWarning); tinygettext::Log::set_log_info_callback(0); try { // FIXME force set language using System::get_language() to get it from env dictionary_manager.set_language(tinygettext::Language::from_env(System::get_language())); parse_args(argc, argv); // here language and po dir isn't set, no traslation in command line init_path_finder(); // here init language path read_rc_file(); // here set language if ~/.pingus/config exist and language value is set apply_args(); // here set language if arg -l is specified print_greeting_message(); // init the display FramebufferType fbtype = SDL_FRAMEBUFFER; if (cmd_options.framebuffer_type.is_set()) { fbtype = cmd_options.framebuffer_type.get(); } bool fullscreen = cmd_options.fullscreen.is_set() ? cmd_options.fullscreen.get() : false; bool resizable = cmd_options.resizable.is_set() ? cmd_options.resizable.get() : true; Size screen_size(800, 600); if (fullscreen) { if (cmd_options.fullscreen_resolution.is_set()) { screen_size = cmd_options.fullscreen_resolution.get(); } } else { if (cmd_options.geometry.is_set()) { screen_size = cmd_options.geometry.get(); } } SDLSystem system; try { system.create_window(fbtype, screen_size, fullscreen, resizable); } catch(const std::exception& err) { if (fbtype == SDL_FRAMEBUFFER) { throw; } else { log_error("couldn't create window, falling back to SDL: " << err.what()); system.create_window(SDL_FRAMEBUFFER, screen_size, fullscreen, resizable); config_manager.set_renderer(SDL_FRAMEBUFFER); } } // init other components SavegameManager savegame_manager("savegames/savegames.scm"); StatManager stat_manager("savegames/variables.scm"); // FIXME: turn these into RAII Resource::init(); Fonts::init(); Sound::PingusSound::init(); config_manager.apply(cmd_options); // start and run the actual game start_game(); } catch (const std::bad_alloc&) { std::cout << _("Pingus: Out of memory!") << std::endl; } catch (const std::exception& a) { std::cout << _("Pingus: Standard exception caught!:\n") << a.what() << std::endl; } catch (...) { std::cout << _("Pingus: Unknown throw caught!") << std::endl; } Sound::PingusSound::deinit(); Fonts::deinit(); WorldObjFactory::deinit(); Resource::deinit(); return 0; }
static void init_tinygettext() { dictionary_manager.add_directory("locale"); dictionary_manager.set_charset("UTF-8"); }
OptionMenu::OptionMenu() : background(), ok_button(), x_pos(), y_pos(), options(), fullscreen_box(), swcursor_box(), autoscroll_box(), mousegrab_box(), printfps_box(), master_volume_box(), sound_volume_box(), music_volume_box(), defaults_label(), defaults_box(), connections(), language(), language_map() { background = Sprite("core/menu/optionmenu"); gui_manager->add(ok_button = new OptionMenuCloseButton(this, Display::get_width()/2 + 225, Display::get_height()/2 + 125)); x_pos = 0; y_pos = 0; int resolutions[][2] = { { 640, 480 }, // 4:3, VGA { 768, 576 }, // 4:3, PAL { 800, 480 }, // Nokia N770, N800 { 800, 600 }, // 4:3, SVGA { 1024, 768 }, // 4:3, XGA { 1152, 864 }, // 4:3 { 1280, 720 }, // 16:9, HD-TV, 720p { 1280, 960 }, // 4:3 { 1280, 1024 }, // 5:4 { 1366, 768 }, // ~16:9, Wide XGA { 1440, 900, }, // 16:10 { 1600, 1200 }, // 4:3, UXGA { 1680, 1050 }, // 16:10, WSXGA { 1920, 1080 }, // 16:9, HD-TV, 1080p { 1920, 1200 }, // 16:10 { -1, -1 } }; int current_choice = -1; int n; ChoiceBox* resolution_box = new ChoiceBox(Rect()); for (n = 0; resolutions[n][0] != -1; ++n) { std::ostringstream ostr; ostr << resolutions[n][0] << "x" << resolutions[n][1]; resolution_box->add_choice(ostr.str()); if (Display::get_width() == resolutions[n][0] && Display::get_height() == resolutions[n][1]) { current_choice = n; } } resolution_box->add_choice("Custom"); if (current_choice == -1) current_choice = n; resolution_box->set_current_choice(current_choice); tinygettext::Language current_language = dictionary_manager.get_language(); language = current_language; n = 0; ChoiceBox* language_box = new ChoiceBox(Rect()); std::set<tinygettext::Language> languages = dictionary_manager.get_languages(); for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); ++i) { language_box->add_choice(i->str()); if (current_language == *i) language_box->set_current_choice(current_choice); } ChoiceBox* scroll_box = new ChoiceBox(Rect()); scroll_box->add_choice("Drag&Drop"); scroll_box->add_choice("Rubberband"); swcursor_box = new CheckBox(Rect()); fullscreen_box = new CheckBox(Rect()); autoscroll_box = new CheckBox(Rect()); mousegrab_box = new CheckBox(Rect()); printfps_box = new CheckBox(Rect()); master_volume_box = new SliderBox(Rect()); sound_volume_box = new SliderBox(Rect()); music_volume_box = new SliderBox(Rect()); C(swcursor_box->on_change.connect(std::bind(&OptionMenu::on_swcursor_change, this, std::placeholders::_1))); C(fullscreen_box->on_change.connect(std::bind(&OptionMenu::on_fullscreen_change, this, std::placeholders::_1))); C(autoscroll_box->on_change.connect(std::bind(&OptionMenu::on_autoscroll_change, this, std::placeholders::_1))); C(mousegrab_box->on_change.connect(std::bind(&OptionMenu::on_mousegrab_change, this, std::placeholders::_1))); C(printfps_box->on_change.connect(std::bind(&OptionMenu::on_printfps_change, this, std::placeholders::_1))); C(master_volume_box->on_change.connect(std::bind(&OptionMenu::on_master_volume_change, this, std::placeholders::_1))); C(sound_volume_box->on_change.connect(std::bind(&OptionMenu::on_sound_volume_change, this, std::placeholders::_1))); C(music_volume_box->on_change.connect(std::bind(&OptionMenu::on_music_volume_change, this, std::placeholders::_1))); C(language_box->on_change.connect(std::bind(&OptionMenu::on_language_change, this, std::placeholders::_1))); C(resolution_box->on_change.connect(std::bind(&OptionMenu::on_resolution_change, this, std::placeholders::_1))); add_item(_("Language:"), language_box); // add_item(_("Scroll Mode:"), scroll_box); add_item(_("Resolution:"), resolution_box); add_item(_("Fullscreen:"), fullscreen_box); add_item(_("Master Volume:"), master_volume_box); add_item(_("Sound Volume:"), sound_volume_box); add_item(_("Music Volume:"), music_volume_box); add_item(_("Autoscrolling:"), autoscroll_box); add_item(_("Print FPS:"), printfps_box); add_item(_("Mouse Grab:"), mousegrab_box); add_item(_("Software Cursor:"), swcursor_box); // Connect with ConfigManager mousegrab_box->set_state(config_manager.get_mouse_grab(), false); C(config_manager.on_mouse_grab_change.connect(std::bind(&CheckBox::set_state, mousegrab_box, std::placeholders::_1, false))); printfps_box->set_state(config_manager.get_print_fps(), false); C(config_manager.on_print_fps_change.connect(std::bind(&CheckBox::set_state, printfps_box, std::placeholders::_1, false))); fullscreen_box->set_state(config_manager.get_fullscreen(), false); C(config_manager.on_fullscreen_change.connect(std::bind(&CheckBox::set_state, fullscreen_box, std::placeholders::_1, false))); swcursor_box->set_state(config_manager.get_swcursor(), false); C(config_manager.on_swcursor_change.connect(std::bind(&CheckBox::set_state, swcursor_box, std::placeholders::_1, false))); autoscroll_box->set_state(config_manager.get_autoscroll(), false); C(config_manager.on_autoscroll_change.connect(std::bind(&CheckBox::set_state, autoscroll_box, std::placeholders::_1, false))); defaults_label = new Label(_("Reset to Defaults:"), Rect(Vector2i(Display::get_width()/2 - 100, Display::get_height()/2 + 160), Size(170, 32))); gui_manager->add(defaults_label); defaults_box = new CheckBox(Rect(Vector2i(Display::get_width()/2 - 100 + 170, Display::get_height()/2 + 160), Size(32, 32))); gui_manager->add(defaults_box); }
const char * GUI_TRANSLATE(const char * msgid) { return dictionaryGUIManager.get_dictionary().translate(msgid); }
std::string GUI_TRANSLATE(const std::string& msgid) { return dictionaryGUIManager.get_dictionary().translate(msgid); }
std::string N_(const std::string& msg, const std::string& msg_pl, int num) { return dictionary_manager.get_dictionary().translate(msg, msg_pl, num); }
std::string _(const std::string& msg) { return dictionary_manager.get_dictionary().translate(msg); }