Rework GetDesiredLanguage + Remove LanguageCode alias type

This commit is contained in:
sspacelynx 2021-08-28 14:51:05 +02:00 committed by ◱ Mark
parent 6135f531ae
commit ca97517d81
4 changed files with 32 additions and 23 deletions

View File

@ -7,8 +7,6 @@
#include <common.h>
namespace skyline {
using LanguageCode = u64;
namespace constant {
constexpr size_t OldLanguageCodeListSize{15}; //!< The size of the pre 4.0.0 language code list
constexpr size_t NewLanguageCodeListSize{18}; //!< The size of the post 10.1.0 language code list (was 17 between 4.0.0 - 10.1.0)
@ -54,28 +52,28 @@ namespace skyline {
SimplifiedChinese,
};
constexpr std::array<LanguageCode, constant::NewLanguageCodeListSize> LanguageCodeList{
util::MakeMagic<LanguageCode>("ja"),
util::MakeMagic<LanguageCode>("en-US"),
util::MakeMagic<LanguageCode>("fr"),
util::MakeMagic<LanguageCode>("de"),
util::MakeMagic<LanguageCode>("it"),
util::MakeMagic<LanguageCode>("es"),
util::MakeMagic<LanguageCode>("zh-CN"),
util::MakeMagic<LanguageCode>("ko"),
util::MakeMagic<LanguageCode>("nl"),
util::MakeMagic<LanguageCode>("pt"),
util::MakeMagic<LanguageCode>("ru"),
util::MakeMagic<LanguageCode>("zh-TW"),
util::MakeMagic<LanguageCode>("en-GB"),
util::MakeMagic<LanguageCode>("fr-CA"),
util::MakeMagic<LanguageCode>("es-419"),
util::MakeMagic<LanguageCode>("zh-Hans"),
util::MakeMagic<LanguageCode>("zh-Hant"),
util::MakeMagic<LanguageCode>("pt-BR"),
constexpr std::array<u64, constant::NewLanguageCodeListSize> LanguageCodeList{
util::MakeMagic<u64>("ja"),
util::MakeMagic<u64>("en-US"),
util::MakeMagic<u64>("fr"),
util::MakeMagic<u64>("de"),
util::MakeMagic<u64>("it"),
util::MakeMagic<u64>("es"),
util::MakeMagic<u64>("zh-CN"),
util::MakeMagic<u64>("ko"),
util::MakeMagic<u64>("nl"),
util::MakeMagic<u64>("pt"),
util::MakeMagic<u64>("ru"),
util::MakeMagic<u64>("zh-TW"),
util::MakeMagic<u64>("en-GB"),
util::MakeMagic<u64>("fr-CA"),
util::MakeMagic<u64>("es-419"),
util::MakeMagic<u64>("zh-Hans"),
util::MakeMagic<u64>("zh-Hant"),
util::MakeMagic<u64>("pt-BR"),
};
constexpr LanguageCode GetLanguageCode(SystemLanguage language) {
constexpr u64 GetLanguageCode(SystemLanguage language) {
return LanguageCodeList.at(static_cast<size_t>(language));
}

View File

@ -34,7 +34,12 @@ namespace skyline::service::am {
}
Result IApplicationFunctions::GetDesiredLanguage(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
response.Push(languages::GetLanguageCode(state.os->systemLanguage));
auto desiredLanguage{languages::GetApplicationLanguage(state.os->systemLanguage)};
if ((1 << static_cast<u32>(desiredLanguage) & state.loader->nacp->nacpContents.supportedLanguageFlag) == 0)
desiredLanguage = state.loader->nacp->GetFirstSupportedLanguage();
response.Push(languages::GetLanguageCode(languages::GetSystemLanguage(desiredLanguage)));
return {};
}

View File

@ -21,6 +21,10 @@ namespace skyline::vfs {
return static_cast<languages::ApplicationLanguage>(std::countr_zero(supportedTitleLanguages));
}
languages::ApplicationLanguage NACP::GetFirstSupportedLanguage() {
return static_cast<languages::ApplicationLanguage>(std::countr_zero(nacpContents.supportedLanguageFlag));
}
std::string NACP::GetApplicationName(languages::ApplicationLanguage language) {
auto applicationName{span(nacpContents.titleEntries.at(static_cast<size_t>(language)).applicationName)};
return std::string(applicationName.as_string(true));

View File

@ -39,6 +39,8 @@ namespace skyline::vfs {
languages::ApplicationLanguage GetFirstSupportedTitleLanguage();
languages::ApplicationLanguage GetFirstSupportedLanguage();
std::string GetApplicationName(languages::ApplicationLanguage language);
std::string GetApplicationPublisher(languages::ApplicationLanguage language);