AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AI18n.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12//
   13// Created by alex2 on 07.11.2020.
   14//
   15
   16#pragma once
   17
   18#include <AUI/Common/AString.h>
   19#include <AUI/Common/AMap.h>
   20#include <AUI/IO/IInputStream.h>
   21#include "ALanguageCode.h"
   22
   27class API_AUI_CORE AI18n {
   28    friend class Lang;
   29private:
   30    AMap<AString, AString> mLangData;
   31
   32    static void loadFromStreamInto(const _<IInputStream>& iis, AMap<AString, AString>& langData);
   33public:
   34    AI18n();
   35
   36    static AI18n& inst();
   37
   38    void loadFromLang(const ALanguageCode& languageCode);
   39    void loadFromStream(const _<IInputStream>& iis);
   40
   41    static ALanguageCode userLanguage();
   42
   43    const AMap<AString, AString>& getLangData() const {
   44        return mLangData;
   45    }
   46};
   47
   48
   49inline AString operator""_i18n(const char* input, size_t s)
   50{
   51    auto i = AI18n::inst().getLangData().find(AString(input));
   52    if (i == AI18n::inst().getLangData().end())
   53        return input;
   54    return i->second;
   55}
Represents a language code in ISO 639-1, for example, en-US or ru-RU.
Definition ALanguageCode.h:25
A std::map with AUI extensions.
Definition AMap.h:218
Represents a Unicode character string.
Definition AString.h:38
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179