🧹 move locale get into gucc

This commit is contained in:
Vladislav Nepogodin 2024-07-06 01:41:00 +04:00
parent 4b35d00724
commit 2a88ecd313
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9
3 changed files with 13 additions and 1 deletions

View File

@ -1,7 +1,9 @@
#ifndef LOCALE_HPP
#define LOCALE_HPP
#include <string> // for string
#include <string_view> // for string_view
#include <vector> // 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<std::string>;
} // namespace gucc::locale
#endif // LOCALE_HPP

View File

@ -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<std::string> {
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

View File

@ -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{};