~aleteoryx/muditaos

ref: be1e6f7523040d07259d9c5cc84e695343e40a86 muditaos/module-utils/i18n/i18nImpl.hpp -rw-r--r-- 1.9 KiB
be1e6f75 — Paweł Joński [BH-1303] Fix flat settings 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <mutex.hpp>
#include <json11.hpp>
#include <i18n/i18n.hpp>

namespace utils
{
    class i18n
    {
      private:
        json11::Json displayLanguage;
        json11::Json fallbackLanguage; // backup language if item not found
        Language fallbackLanguageName = getDefaultLanguage();
        Language inputLanguage        = fallbackLanguageName;
        Language inputLanguageFilename;
        Language currentDisplayLanguage;
        std::filesystem::path InputLanguageDirPath   = "assets/profiles";
        std::filesystem::path DisplayLanguageDirPath = "assets/lang";
        mutable cpp_freertos::MutexStandard mutex;

        void changeDisplayLanguage(const json11::Json &lang);
        void loadFallbackLanguage();

      protected:
        const std::string &get(const std::string &str);
        json11::Json &getDisplayLanguageJSON()
        {
            return displayLanguage;
        }
        json11::Json &getFallbackLanguageJSON()
        {
            return fallbackLanguage;
        }
        const std::string &getDisplayLanguage()
        {
            return currentDisplayLanguage;
        }
        const std::string &getInputLanguage()
        {
            return inputLanguage;
        }
        const std::string &getInputLanguageFilename(const std::string &inputMode);
        bool setInputLanguage(const Language &lang);
        bool setDisplayLanguage(const Language &lang);
        const std::filesystem::path getInputLanguagePath()
        {
            return InputLanguageDirPath;
        }
        const std::filesystem::path getDisplayLanguagePath()
        {
            return DisplayLanguageDirPath;
        }

        void resetDisplayLanguages();
        void resetAssetsPath(const std::filesystem::path &);
    };

} // namespace utils