You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-12 13:20:55 +00:00
Added translation support to Godot
included is a French translation!
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -821,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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user