3#include "ll/api/Expected.h"
4#include "ll/api/base/Concepts.h"
5#include "ll/api/base/FixedString.h"
11#include "fmt/compile.h"
12#include "fmt/format.h"
14#include "fmt/ranges.h"
21LLNDAPI std::string_view getDefaultLocaleCode();
25 std::unique_ptr<Impl> impl;
31 LLNDAPI Expected<> load(std::filesystem::path
const& path)
noexcept;
35 LLAPI
void set(std::string_view localeCode, std::string_view key, std::string_view value);
37 LLNDAPI std::string_view get(std::string_view key, std::string_view localeCode)
const;
40inline I18n& getInstance() {
47#ifdef LL_I18N_COLLECT_STRINGS
48#include "ll/api/reflection/TypeName.h"
50#ifndef LL_I18N_STRING_LITERAL_TYPE
51#define LL_I18N_STRING_LITERAL_TYPE ::ll::FixedStrWithLoc
54namespace ll::i18n::detail {
55template <LL_I18N_STRING_LITERAL_TYPE str>
57#ifndef LL_I18N_COLLECT_STRINGS_CUSTOM
58template <LL_I18N_STRING_LITERAL_TYPE str>
60 static inline int _ = [] {
61 fmt::print(
"\"{0}\": \"{0}\", // at {1}\n", str.sv(), str.loc().toString());
68#ifndef LL_I18N_STRING_LITERAL_TYPE
69#define LL_I18N_STRING_LITERAL_TYPE ::ll::FixedString
72namespace ll::inline literals::inline i18n_literals {
73template <LL_I18N_STRING_LITERAL_TYPE Fmt>
74[[nodiscard]]
constexpr auto operator""_tr() {
75#ifdef LL_I18N_COLLECT_STRINGS
76 static i18n::detail::TrStrOut<Fmt> e{};
78 return [=]<
class... Args>(Args&&... args) {
79 [[maybe_unused]]
static constexpr auto checker = fmt::format_string<Args...>(Fmt.sv());
80 return fmt::vformat(i18n::getInstance().get(Fmt.sv(), {}), fmt::make_format_args(args...));
83template <LL_I18N_STRING_LITERAL_TYPE Fmt>
84[[nodiscard]]
constexpr auto operator""_trl() {
85#ifdef LL_I18N_COLLECT_STRINGS
86 static i18n::detail::TrStrOut<Fmt> e{};
88 return [=]<
class... Args>(std::string_view localeCode, Args&&... args) {
89 [[maybe_unused]]
static constexpr auto checker = fmt::format_string<Args...>(Fmt.sv());
90 return fmt::vformat(i18n::getInstance().get(Fmt.sv(), localeCode), fmt::make_format_args(args...));