Skip to content

Commit

Permalink
commit 2 regarding review
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiMiao committed Jan 20, 2021
1 parent 6691a96 commit 38ac446
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
5 changes: 2 additions & 3 deletions library/include/borealis/i18n.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ void loadTranslations();
*/
std::string getCurrentLocale();

#ifdef __SWITCH__
/**
* Returns the current system locale id
* this id only make sense for libnx
* NOT the one that's currently used in the app!
*/
int swGetCurrentLocaleID();
#endif
int nxGetCurrentLocaleID();

inline namespace literals
{
Expand Down
46 changes: 23 additions & 23 deletions library/lib/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ bool Application::init(std::string title, Style* style, LibraryViewsThemeVariant
#ifdef __SWITCH__
{
PlFontData font;
int locale = i18n::swGetCurrentLocaleID();
SetLanguage localeID = (SetLanguage)i18n::nxGetCurrentLocaleID();

// Standard font
Result rc = plGetSharedFontByType(&font, PlSharedFontType_Standard);
if (R_SUCCEEDED(rc))
{
Logger::info("Adding Switch shared standard font");
Application::fontStash.standard = Application::loadFontFromMemory("regular", font.address, font.size, false);
Application::fontStash.standard = Application::loadFontFromMemory("standard", font.address, font.size, false);
}

// Load other fonts on demand
Expand All @@ -245,10 +245,10 @@ bool Application::init(std::string title, Style* style, LibraryViewsThemeVariant
if (at == AppletType_Application || at == AppletType_SystemApplication) // title takeover
{
isFullFallback = true;
Logger::warning("Non applet mode, font full fallback is enabled!");
Logger::info("Non applet mode, font full fallback is enabled!");
}

if (locale == 6 || locale == 15 || isFullFallback)
if (localeID == SetLanguage_ZHCN || localeID == SetLanguage_ZHHANS || isFullFallback)
{
// S.Chinese font
rc = plGetSharedFontByType(&font, PlSharedFontType_ChineseSimplified);
Expand All @@ -265,7 +265,7 @@ bool Application::init(std::string title, Style* style, LibraryViewsThemeVariant
Application::fontStash.extSchinese = Application::loadFontFromMemory("extSchinese", font.address, font.size, false);
}
}
if (locale == 11 || locale == 16 || isFullFallback)
if (localeID == SetLanguage_ZHTW || localeID == SetLanguage_ZHHANT || isFullFallback)
{
// T.Chinese font
rc = plGetSharedFontByType(&font, PlSharedFontType_ChineseTraditional);
Expand All @@ -275,7 +275,7 @@ bool Application::init(std::string title, Style* style, LibraryViewsThemeVariant
Application::fontStash.tchinese = Application::loadFontFromMemory("tchinese", font.address, font.size, false);
}
}
if (locale == 7 || isFullFallback)
if (localeID == SetLanguage_KO || isFullFallback)
{
// Korean font
rc = plGetSharedFontByType(&font, PlSharedFontType_KO);
Expand All @@ -287,33 +287,33 @@ bool Application::init(std::string title, Style* style, LibraryViewsThemeVariant
}

// Sequentially fallback to other fonts and decide regular font, also on demand
switch (locale)
switch (localeID)
{
case 6 :
case 15 :
case SetLanguage_ZHCN :
case SetLanguage_ZHHANS :
if (isFullFallback)
{
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.korean);
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.standard);
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.tchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.extSchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.tchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.standard);
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.korean);
}
else
{
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.standard);
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.extSchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.standard);
}
Logger::info("Using Switch shared S.Chinese font as regular");
Application::fontStash.regular = Application::fontStash.schinese;
break;
case 11 :
case 16 :
case SetLanguage_ZHTW :
case SetLanguage_ZHHANT :
if (isFullFallback)
{
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.korean);
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.standard);
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.extSchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.schinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.extSchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.standard);
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.korean);
}
else
{
Expand All @@ -322,13 +322,13 @@ bool Application::init(std::string title, Style* style, LibraryViewsThemeVariant
Logger::info("Using Switch shared T.Chinese font as regular");
Application::fontStash.regular = Application::fontStash.tchinese;
break;
case 7 :
case SetLanguage_KO :
if (isFullFallback)
{
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.standard);
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.tchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.extSchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.schinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.extSchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.tchinese);
}
else
{
Expand All @@ -340,10 +340,10 @@ bool Application::init(std::string title, Style* style, LibraryViewsThemeVariant
default:
if (isFullFallback)
{
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.schinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.extSchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.korean);
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.tchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.extSchinese);
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.schinese);
}
Logger::info("Using Switch shared standard font as regular");
Application::fontStash.regular = Application::fontStash.standard;
Expand Down
12 changes: 6 additions & 6 deletions library/lib/i18n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ std::string getCurrentLocale()
}
else
{
brls::Logger::error("Unable to get system language (error 0x{0:x}), using the default one: {1}", res, DEFAULT_LOCALE);
brls::Logger::error("Unable to get system language (error {0:#x}), using the default one: {1}", res, DEFAULT_LOCALE);
}
#endif
return DEFAULT_LOCALE;
}

#ifdef __SWITCH__
int swGetCurrentLocaleID()
int nxGetCurrentLocaleID()
{
#ifdef __SWITCH__
u64 languageCode = 0;
SetLanguage setlanguage = SetLanguage_ENUS;

Expand All @@ -125,16 +125,16 @@ int swGetCurrentLocaleID()
}
else
{
brls::Logger::error("Unable to convert system language ID (error 0x{0:x}), using the default one: {1}", res, DEFAULT_LOCALE);
brls::Logger::error("Unable to convert system language ID (error {0:#x}), using the default one: {1}", res, DEFAULT_LOCALE);
}
}
else
{
brls::Logger::error("Unable to get system language (error 0x{0:x}), using the default one: {1}", res, DEFAULT_LOCALE);
brls::Logger::error("Unable to get system language (error {0:#x}), using the default one: {1}", res, DEFAULT_LOCALE);
}
#endif
return 1; // SetLanguage_ENUS
}
#endif

void loadTranslations()
{
Expand Down

0 comments on commit 38ac446

Please sign in to comment.