i18n::get should accept a string_view rather than char*, simplifies calling.
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace sphaira::i18n {
|
||||
|
||||
bool init(long index);
|
||||
void exit();
|
||||
|
||||
std::string get(const char* str);
|
||||
std::string get(std::string_view str);
|
||||
|
||||
} // namespace sphaira::i18n
|
||||
|
||||
|
||||
@@ -1588,7 +1588,7 @@ void App::DisplayAdvancedOptions(bool left_side) {
|
||||
}
|
||||
));
|
||||
}
|
||||
}, i18n::get(g_app->m_right_side_menu.Get().c_str())));
|
||||
}, i18n::get(g_app->m_right_side_menu.Get())));
|
||||
|
||||
options->Add(std::make_shared<ui::SidebarEntryCallback>("Install options"_i18n, [left_side](){
|
||||
App::DisplayInstallOptions(left_side);
|
||||
|
||||
@@ -13,8 +13,8 @@ yyjson_doc* json;
|
||||
yyjson_val* root;
|
||||
std::unordered_map<std::string, std::string> g_tr_cache;
|
||||
|
||||
std::string get_internal(const char* str, size_t len) {
|
||||
const std::string kkey = {str, len};
|
||||
std::string get_internal(std::string_view str) {
|
||||
const std::string kkey = {str.data(), str.length()};
|
||||
|
||||
if (auto it = g_tr_cache.find(kkey); it != g_tr_cache.end()) {
|
||||
return it->second;
|
||||
@@ -28,7 +28,7 @@ std::string get_internal(const char* str, size_t len) {
|
||||
return kkey;
|
||||
}
|
||||
|
||||
auto key = yyjson_obj_getn(root, str, len);
|
||||
auto key = yyjson_obj_getn(root, str.data(), str.length());
|
||||
if (!key) {
|
||||
log_write("\tfailed to find key: [%s]\n", kkey.c_str());
|
||||
return kkey;
|
||||
@@ -134,8 +134,8 @@ void exit() {
|
||||
g_i18n_data.clear();
|
||||
}
|
||||
|
||||
std::string get(const char* str) {
|
||||
return get_internal(str, std::strlen(str));
|
||||
std::string get(std::string_view str) {
|
||||
return get_internal(str);
|
||||
}
|
||||
|
||||
} // namespace sphaira::i18n
|
||||
@@ -143,7 +143,7 @@ std::string get(const char* str) {
|
||||
namespace literals {
|
||||
|
||||
std::string operator"" _i18n(const char* str, size_t len) {
|
||||
return sphaira::i18n::get_internal(str, len);
|
||||
return sphaira::i18n::get_internal({str, len});
|
||||
}
|
||||
|
||||
} // namespace literals
|
||||
|
||||
@@ -23,7 +23,7 @@ using MetaEntries = std::vector<NsApplicationContentMetaStatus>;
|
||||
Result Notify(Result rc, const std::string& error_message) {
|
||||
if (R_FAILED(rc)) {
|
||||
App::Push(std::make_shared<ui::ErrorBox>(rc,
|
||||
i18n::get(error_message.c_str())
|
||||
i18n::get(error_message)
|
||||
));
|
||||
} else {
|
||||
App::Notify("Success");
|
||||
|
||||
@@ -44,10 +44,10 @@ SidebarEntryBool::SidebarEntryBool(std::string title, bool option, Callback cb,
|
||||
, m_false_str{std::move(false_str)} {
|
||||
|
||||
if (m_true_str == "On") {
|
||||
m_true_str = i18n::get(m_true_str.c_str());
|
||||
m_true_str = i18n::get(m_true_str);
|
||||
}
|
||||
if (m_false_str == "Off") {
|
||||
m_false_str = i18n::get(m_false_str.c_str());
|
||||
m_false_str = i18n::get(m_false_str);
|
||||
}
|
||||
|
||||
SetAction(Button::A, Action{"OK"_i18n, [this](){
|
||||
|
||||
Reference in New Issue
Block a user