Repository: godotengine/godot
File: editor/settings/editor_settings.cpp (C++)

Code before:
	}

	// Skip locales which we can't render properly.
	const LocalVector<String> locales_to_skip = _get_skipped_locales();
	const String host_lang = OS::get_singleton()->get_locale();

	String best = "en";
	int best_score = 0;
	for (const String &locale : get_editor_locales()) {
		// Test against language code without regional variants (e.g. ur_PK).
		String lang_code = locale.get_slicec('_', 0);
		if (locales_to_skip.has(lang_code)) {
			continue;
		}

		int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
		if (score > 0 && score >= best_score) {
			best = locale;
			best_score = score;
		}
	}

	return best;
}

// Shortcuts

void EditorSettings::_add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut) {
	shortcuts[p_name] = p_shortcut;
}

void EditorSettings::add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut) {
	shortcuts[p_name] = p_shortcut;
	shortcuts[p_name]->set_meta("customized", true);
}

bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
	HashMap<String, Ref<Shortcut>>::ConstIterator E = shortcuts.find(p_name);
	ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");

	return E->value->matches_event(p_event);
}

Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
	HashMap<String, Ref<Shortcut>>::ConstIterator SC = shortcuts.find(p_name);
	if (SC) {
		return SC->value;
	}

	// If no shortcut with the provided name is found in the list, check the built-in shortcuts.
	// Use the first item in the action list for the shortcut event, since a shortcut can only have 1 linked event.

Review comment (performance):
Isn't it a bit wasteful to redo this processing everytime `get_language()` is called? I would assume it to be a cached value saved when determining it the first time.

Code after:
	}

	if (auto_language.is_empty()) {
		// Skip locales which we can't render properly.
		const LocalVector<String> locales_to_skip = _get_skipped_locales();
		const String host_lang = OS::get_singleton()->get_locale();

		String best = "en";
		int best_score = 0;
		for (const String &locale : get_editor_locales()) {
			// Test against language code without regional variants (e.g. ur_PK).
			String lang_code = locale.get_slicec('_', 0);
			if (locales_to_skip.has(lang_code)) {
				continue;
			}

			int score = TranslationServer::get_singleton()->compare_locales(host_lang, locale);
			if (score > 0 && score >= best_score) {
				best = locale;
				best_score = score;
			}
		}
		auto_language = best;
	}
	return auto_language;
}

// Shortcuts

void EditorSettings::_add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut) {
	shortcuts[p_name] = p_shortcut;
}

void EditorSettings::add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut) {
	shortcuts[p_name] = p_shortcut;
	shortcuts[p_name]->set_meta("customized", true);
}

bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
	HashMap<String, Ref<Shortcut>>::ConstIterator E = shortcuts.find(p_name);
	ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + ".");

	return E->value->matches_event(p_event);
}

Ref<Shortcut> EditorSettings::get_shortcut(const String &p_name) const {
	HashMap<String, Ref<Shortcut>>::ConstIterator SC = shortcuts.find(p_name);
	if (SC) {
		return SC->value;
	}