Skip to content

Commit

Permalink
🧹 move locale get into gucc
Browse files Browse the repository at this point in the history
  • Loading branch information
vnepogodin committed Jul 5, 2024
1 parent 4b35d00 commit 2a88ecd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gucc/include/gucc/locale.hpp
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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
5 changes: 5 additions & 0 deletions gucc/src/locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/tui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

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

0 comments on commit 2a88ecd

Please sign in to comment.