You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-21 14:57:09 +00:00
Allow localizing the application name with project translations
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/plist.h"
|
||||
#include "core/string/translation.h"
|
||||
#include "core/string/translation_server.h"
|
||||
#include "drivers/png/png_driver_common.h"
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_string_names.h"
|
||||
@@ -1757,7 +1757,6 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized");
|
||||
Dictionary microphone_usage_descriptions = p_preset->get("privacy/microphone_usage_description_localized");
|
||||
Dictionary camera_usage_descriptions = p_preset->get("privacy/camera_usage_description_localized");
|
||||
Dictionary location_usage_descriptions = p_preset->get("privacy/location_usage_description_localized");
|
||||
@@ -1771,15 +1770,21 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
|
||||
Dictionary removable_volumes_usage_descriptions = p_preset->get("privacy/removable_volumes_usage_description_localized");
|
||||
Dictionary copyrights = p_preset->get("application/copyright_localized");
|
||||
|
||||
Vector<String> translations = get_project_setting(p_preset, "internationalization/locale/translations");
|
||||
if (translations.size() > 0) {
|
||||
const String project_name = get_project_setting(p_preset, "application/config/name");
|
||||
const Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized");
|
||||
const StringName domain_name = "godot.project_name_localization";
|
||||
Ref<TranslationDomain> domain = TranslationServer::get_singleton()->get_or_add_domain(domain_name);
|
||||
TranslationServer::get_singleton()->load_project_translations(domain);
|
||||
const Vector<String> locales = domain->get_loaded_locales();
|
||||
|
||||
if (!locales.is_empty()) {
|
||||
{
|
||||
String fname = tmp_app_path_name + "/Contents/Resources/en.lproj";
|
||||
tmp_app_dir->make_dir_recursive(fname);
|
||||
Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
|
||||
f->store_line("/* Localized versions of Info.plist keys */");
|
||||
f->store_line("");
|
||||
f->store_line("CFBundleDisplayName = \"" + get_project_setting(p_preset, "application/config/name").operator String() + "\";");
|
||||
f->store_line("CFBundleDisplayName = \"" + project_name + "\";");
|
||||
if (!((String)p_preset->get("privacy/microphone_usage_description")).is_empty()) {
|
||||
f->store_line("NSMicrophoneUsageDescription = \"" + p_preset->get("privacy/microphone_usage_description").operator String() + "\";");
|
||||
}
|
||||
@@ -1816,23 +1821,27 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
|
||||
f->store_line("NSHumanReadableCopyright = \"" + p_preset->get("application/copyright").operator String() + "\";");
|
||||
}
|
||||
|
||||
HashSet<String> languages;
|
||||
for (const String &E : translations) {
|
||||
Ref<Translation> tr = ResourceLoader::load(E);
|
||||
if (tr.is_valid() && tr->get_locale() != "en") {
|
||||
languages.insert(tr->get_locale());
|
||||
for (const String &lang : locales) {
|
||||
if (lang == "en") {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (const String &lang : languages) {
|
||||
String fname = tmp_app_path_name + "/Contents/Resources/" + lang + ".lproj";
|
||||
tmp_app_dir->make_dir_recursive(fname);
|
||||
Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE);
|
||||
f->store_line("/* Localized versions of Info.plist keys */");
|
||||
f->store_line("");
|
||||
if (appnames.has(lang)) {
|
||||
|
||||
if (appnames.is_empty()) {
|
||||
domain->set_locale_override(lang);
|
||||
const String &name = domain->translate(project_name, String());
|
||||
if (name != project_name) {
|
||||
f->store_line("CFBundleDisplayName = \"" + name + "\";");
|
||||
}
|
||||
} else if (appnames.has(lang)) {
|
||||
f->store_line("CFBundleDisplayName = \"" + appnames[lang].operator String() + "\";");
|
||||
}
|
||||
|
||||
if (microphone_usage_descriptions.has(lang)) {
|
||||
f->store_line("NSMicrophoneUsageDescription = \"" + microphone_usage_descriptions[lang].operator String() + "\";");
|
||||
}
|
||||
@@ -1872,6 +1881,8 @@ Error EditorExportPlatformMacOS::export_project(const Ref<EditorExportPreset> &p
|
||||
}
|
||||
}
|
||||
|
||||
TranslationServer::get_singleton()->remove_domain(domain_name);
|
||||
|
||||
// Now process our template.
|
||||
bool found_binary = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user