diff --git a/gucc/include/gucc/locale.hpp b/gucc/include/gucc/locale.hpp index 67766d3..ff18fcc 100644 --- a/gucc/include/gucc/locale.hpp +++ b/gucc/include/gucc/locale.hpp @@ -1,7 +1,9 @@ #ifndef LOCALE_HPP #define LOCALE_HPP +#include // for string #include // for string_view +#include // for vector namespace gucc::locale { @@ -12,6 +14,9 @@ auto set_locale(std::string_view locale, std::string_view mountpoint) noexcept - // Sets without updating system locale auto prepare_locale_set(std::string_view locale, std::string_view mountpoint) noexcept -> bool; +// List possible locales +auto get_possible_locales() noexcept -> std::vector; + } // namespace gucc::locale #endif // LOCALE_HPP diff --git a/gucc/src/locale.cpp b/gucc/src/locale.cpp index 9e9c5f9..e0ebf56 100644 --- a/gucc/src/locale.cpp +++ b/gucc/src/locale.cpp @@ -60,4 +60,9 @@ auto set_locale(std::string_view locale, std::string_view mountpoint) noexcept - return true; } +auto get_possible_locales() noexcept -> std::vector { + const auto& locales = utils::exec("cat /etc/locale.gen | grep -v '# ' | sed 's/#//g' | awk '/UTF-8/ {print $1}'"); + return utils::make_multiline(locales); +} + } // namespace gucc::locale diff --git a/src/tui.cpp b/src/tui.cpp index f82e568..0792ede 100644 --- a/src/tui.cpp +++ b/src/tui.cpp @@ -4,6 +4,7 @@ #include "definitions.hpp" #include "disk.hpp" #include "drivers.hpp" +#include "gucc/locale.hpp" #include "misc.hpp" #include "simple_tui.hpp" #include "utils.hpp" @@ -12,6 +13,7 @@ // import gucc #include "gucc/fs_utils.hpp" #include "gucc/io_utils.hpp" +#include "gucc/locale.hpp" #include "gucc/string_utils.hpp" #include "gucc/zfs.hpp" @@ -178,7 +180,7 @@ void set_hostname() noexcept { // Set system language void set_locale() noexcept { - const auto& locales = gucc::utils::make_multiline(gucc::utils::exec("cat /etc/locale.gen | grep -v \"# \" | sed 's/#//g' | awk '/UTF-8/ {print $1}'")); + const auto& locales = gucc::locale::get_possible_locales(); // System language std::string locale{};