diff options
Diffstat (limited to 'tools/editor/editor_settings.cpp')
-rw-r--r-- | tools/editor/editor_settings.cpp | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index ad990e3fab..0b7e389773 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -41,6 +41,10 @@ #include "io/config_file.h" #include "editor_node.h" #include "globals.h" +#include "translations.h" +#include "io/file_access_memory.h" +#include "io/translation_loader_po.h" +#include "io/compression.h" Ref<EditorSettings> EditorSettings::singleton=NULL; @@ -284,6 +288,7 @@ void EditorSettings::create() { print_line("EditorSettings: Load OK!"); } + singleton->setup_language(); singleton->setup_network(); singleton->load_favorites(); singleton->list_text_editor_themes(); @@ -309,10 +314,12 @@ void EditorSettings::create() { singleton = Ref<EditorSettings>( memnew( EditorSettings ) ); singleton->config_file_path=config_file_path; singleton->settings_path=config_path+"/"+config_dir; - singleton->_load_defaults(extra_config); + singleton->_load_defaults(extra_config); + singleton->setup_language(); singleton->setup_network(); singleton->list_text_editor_themes(); + } String EditorSettings::get_settings_path() const { @@ -322,6 +329,23 @@ String EditorSettings::get_settings_path() const { +void EditorSettings::setup_language() { + + String lang = get("global/editor_language"); + print_line("LANG IS "+lang); + if (lang=="en") + return; //none to do + + for(int i=0;i<translations.size();i++) { + print_line("TESTING "+translations[i]->get_locale()); + if (translations[i]->get_locale()==lang) { + print_line("ok translation"); + TranslationServer::get_singleton()->set_tool_translation(translations[i]); + break; + } + } +} + void EditorSettings::setup_network() { List<IP_Address> local_ip; @@ -389,6 +413,36 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _THREAD_SAFE_METHOD_ + + { + String lang_hint="en"; + String host_lang = OS::get_singleton()->get_locale(); + + String best; + + for(int i=0;i<translations.size();i++) { + String locale = translations[i]->get_locale(); + lang_hint+=","; + lang_hint+=locale; + + if (host_lang==locale) { + best=locale; + } + + if (best==String() && host_lang.begins_with(locale)) { + best=locale; + } + } + + if (best==String()) { + best="en"; + } + + set("global/editor_language",best); + hints["global/editor_language"]=PropertyInfo(Variant::STRING,"global/editor_language",PROPERTY_HINT_ENUM,lang_hint,PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_RESTART_IF_CHANGED); + } + + set("global/show_script_in_scene_tabs",false); set("global/font",""); hints["global/font"]=PropertyInfo(Variant::STRING,"global/font",PROPERTY_HINT_GLOBAL_FILE,"*.fnt"); set("global/autoscan_project_path",""); @@ -399,6 +453,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { hints["global/default_project_export_path"]=PropertyInfo(Variant::STRING,"global/default_project_export_path",PROPERTY_HINT_GLOBAL_DIR); set("global/show_script_in_scene_tabs",false); + set("text_editor/color_theme","Default"); hints["text_editor/color_theme"]=PropertyInfo(Variant::STRING,"text_editor/color_theme",PROPERTY_HINT_ENUM,"Default"); @@ -507,6 +562,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { set("resources/save_compressed_resources",true); set("resources/auto_reload_modified_images",true); + set("import/automatic_reimport_on_sources_changed",true); + if (p_extra_config.is_valid()) { if (p_extra_config->has_section("init_projects") && p_extra_config->has_section_key("init_projects", "list")) { @@ -819,7 +876,32 @@ EditorSettings::EditorSettings() { //singleton=this; last_order=0; + + EditorTranslationList *etl=_editor_translations; + + while(etl->data) { + + Vector<uint8_t> data; + data.resize(etl->uncomp_size); + Compression::decompress(data.ptr(),etl->uncomp_size,etl->data,etl->comp_size,Compression::MODE_DEFLATE); + + FileAccessMemory *fa = memnew (FileAccessMemory); + fa->open_custom(data.ptr(),data.size()); + + Ref<Translation> tr = TranslationLoaderPO::load_translation(fa,NULL,"translation_"+String(etl->lang)); + + if (tr.is_valid()) { + tr->set_locale(etl->lang); + translations.push_back(tr); + } + + etl++; + + } + _load_defaults(); + + } |