mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Allow localizing the application name with project translations
This commit is contained in:
parent
6fd949a6dc
commit
b8a8f8b35a
12 changed files with 100 additions and 57 deletions
|
|
@ -39,6 +39,7 @@
|
|||
#include "core/io/image_loader.h"
|
||||
#include "core/io/json.h"
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/string/translation_server.h"
|
||||
#include "core/version.h"
|
||||
#include "editor/editor_log.h"
|
||||
#include "editor/editor_node.h"
|
||||
|
|
@ -1770,8 +1771,11 @@ void EditorExportPlatformAndroid::_fix_resources(const Ref<EditorExportPreset> &
|
|||
|
||||
Vector<String> string_table;
|
||||
|
||||
String package_name = p_preset->get("package/name");
|
||||
Dictionary appnames = get_project_setting(p_preset, "application/config/name_localized");
|
||||
const String project_name = get_project_name(p_preset, p_preset->get("package/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);
|
||||
|
||||
for (uint32_t i = 0; i < string_count; i++) {
|
||||
uint32_t offset = decode_uint32(&r_manifest[string_table_begins + i * 4]);
|
||||
|
|
@ -1779,24 +1783,24 @@ void EditorExportPlatformAndroid::_fix_resources(const Ref<EditorExportPreset> &
|
|||
|
||||
String str = _parse_string(&r_manifest[offset], string_flags & UTF8_FLAG);
|
||||
|
||||
if (str.begins_with("godot-project-name")) {
|
||||
if (str == "godot-project-name") {
|
||||
//project name
|
||||
str = get_project_name(p_preset, package_name);
|
||||
if (str == "godot-project-name") {
|
||||
str = project_name;
|
||||
} else if (str.begins_with("godot-project-name")) {
|
||||
String lang = str.substr(str.rfind_char('-') + 1).replace_char('-', '_');
|
||||
|
||||
if (appnames.is_empty()) {
|
||||
domain->set_locale_override(lang);
|
||||
str = domain->translate(project_name, String());
|
||||
} else {
|
||||
String lang = str.substr(str.rfind_char('-') + 1).replace_char('-', '_');
|
||||
if (appnames.has(lang)) {
|
||||
str = appnames[lang];
|
||||
} else {
|
||||
str = get_project_name(p_preset, package_name);
|
||||
}
|
||||
str = appnames.get(lang, project_name);
|
||||
}
|
||||
}
|
||||
|
||||
string_table.push_back(str);
|
||||
}
|
||||
|
||||
TranslationServer::get_singleton()->remove_domain(domain_name);
|
||||
|
||||
//write a new string table, but use 16 bits
|
||||
Vector<uint8_t> ret;
|
||||
ret.resize(string_table_begins + string_table.size() * 4);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include "gradle_export_util.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/string/translation_server.h"
|
||||
|
||||
int _get_android_orientation_value(DisplayServer::ScreenOrientation screen_orientation) {
|
||||
switch (screen_orientation) {
|
||||
|
|
@ -219,6 +219,12 @@ Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset
|
|||
}
|
||||
return ERR_CANT_OPEN;
|
||||
}
|
||||
|
||||
// Setup a temporary translation domain to translate the project name.
|
||||
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);
|
||||
|
||||
da->list_dir_begin();
|
||||
while (true) {
|
||||
String file = da->get_next();
|
||||
|
|
@ -231,8 +237,15 @@ Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset
|
|||
}
|
||||
String locale = file.replace("values-", "").replace("-r", "_");
|
||||
String locale_directory = p_gradle_build_dir.path_join("res/" + file + "/godot_project_name_string.xml");
|
||||
if (p_appnames.has(locale)) {
|
||||
String locale_project_name = p_appnames[locale];
|
||||
|
||||
String locale_project_name;
|
||||
if (p_appnames.is_empty()) {
|
||||
domain->set_locale_override(locale);
|
||||
locale_project_name = domain->translate(p_project_name, String());
|
||||
} else {
|
||||
locale_project_name = p_appnames.get(locale, p_project_name);
|
||||
}
|
||||
if (locale_project_name != p_project_name) {
|
||||
String processed_xml_string = vformat(GODOT_PROJECT_NAME_XML_STRING, _android_xml_escape(locale_project_name));
|
||||
print_verbose("Storing project name for locale " + locale + " under " + locale_directory);
|
||||
store_string_at_path(locale_directory, processed_xml_string);
|
||||
|
|
@ -242,6 +255,9 @@ Error _create_project_name_strings_files(const Ref<EditorExportPreset> &p_preset
|
|||
}
|
||||
}
|
||||
da->list_dir_end();
|
||||
|
||||
TranslationServer::get_singleton()->remove_domain(domain_name);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue