3#include "ll/api/Expected.h"
4#include "ll/api/base/Concepts.h"
5#include "ll/api/base/FixedString.h"
11#include "fmt/chrono.h"
13#include "fmt/compile.h"
14#include "fmt/format.h"
16#include "fmt/ranges.h"
23LLNDAPI std::string_view getDefaultLocaleCode();
27 std::unique_ptr<Impl> impl;
33 LLNDAPI Expected<> load(std::filesystem::path
const& path)
noexcept;
37 LLAPI
void set(std::string_view localeCode, std::string_view key, std::string_view value);
39 LLNDAPI std::string_view get(std::string_view key, std::string_view localeCode)
const;
42inline I18n& getInstance() {
49#ifdef LL_I18N_COLLECT_STRINGS
50#include "ll/api/reflection/TypeName.h"
52#ifndef LL_I18N_STRING_LITERAL_TYPE
53#define LL_I18N_STRING_LITERAL_TYPE ::ll::FixedStrWithLoc
56namespace ll::i18n::detail {
57template <LL_I18N_STRING_LITERAL_TYPE str>
59#ifndef LL_I18N_COLLECT_STRINGS_CUSTOM
60template <LL_I18N_STRING_LITERAL_TYPE str>
62 static inline int _ = [] {
63 fmt::print(
"\"{0}\": \"{0}\", // at {1}\n", str.sv(), str.loc().toString());
70#ifndef LL_I18N_STRING_LITERAL_TYPE
71#define LL_I18N_STRING_LITERAL_TYPE ::ll::FixedString
74namespace ll::inline literals::inline i18n_literals {
75template <LL_I18N_STRING_LITERAL_TYPE Fmt>
76[[nodiscard]]
constexpr auto operator""_tr() {
77#ifdef LL_I18N_COLLECT_STRINGS
78 static i18n::detail::TrStrOut<Fmt> e{};
80 return [=]<
class... Args>(Args&&... args) {
81 [[maybe_unused]]
static constexpr auto checker = fmt::format_string<Args...>(Fmt.sv());
82 return fmt::vformat(i18n::getInstance().get(Fmt.sv(), {}), fmt::make_format_args(args...));
85template <LL_I18N_STRING_LITERAL_TYPE Fmt>
86[[nodiscard]]
constexpr auto operator""_trl() {
87#ifdef LL_I18N_COLLECT_STRINGS
88 static i18n::detail::TrStrOut<Fmt> e{};
90 return [=]<
class... Args>(std::string_view localeCode, Args&&... args) {
91 [[maybe_unused]]
static constexpr auto checker = fmt::format_string<Args...>(Fmt.sv());
92 return fmt::vformat(i18n::getInstance().get(Fmt.sv(), localeCode), fmt::make_format_args(args...));