| 1 | // Aseprite | 
|---|
| 2 | // Copyright (C) 2016-2018  David Capello | 
|---|
| 3 | // | 
|---|
| 4 | // This program is distributed under the terms of | 
|---|
| 5 | // the End-User License Agreement for Aseprite. | 
|---|
| 6 |  | 
|---|
| 7 | #ifndef APP_I18N_STRINGS_INCLUDED | 
|---|
| 8 | #define APP_I18N_STRINGS_INCLUDED | 
|---|
| 9 | #pragma once | 
|---|
| 10 |  | 
|---|
| 11 | #include <set> | 
|---|
| 12 | #include <string> | 
|---|
| 13 | #include <unordered_map> | 
|---|
| 14 |  | 
|---|
| 15 | #include "obs/signal.h" | 
|---|
| 16 |  | 
|---|
| 17 | #include "strings.ini.h" | 
|---|
| 18 |  | 
|---|
| 19 | namespace app { | 
|---|
| 20 |  | 
|---|
| 21 | class Preferences; | 
|---|
| 22 | class Extensions; | 
|---|
| 23 |  | 
|---|
| 24 | // Singleton class to load and access "strings/en.ini" file. | 
|---|
| 25 | class Strings : public app::gen::Strings<app::Strings> { | 
|---|
| 26 | public: | 
|---|
| 27 | static void createInstance(Preferences& pref, | 
|---|
| 28 | Extensions& exts); | 
|---|
| 29 | static Strings* instance(); | 
|---|
| 30 |  | 
|---|
| 31 | const std::string& translate(const char* id) const; | 
|---|
| 32 |  | 
|---|
| 33 | std::set<std::string> availableLanguages() const; | 
|---|
| 34 | std::string currentLanguage() const; | 
|---|
| 35 | void setCurrentLanguage(const std::string& langId); | 
|---|
| 36 |  | 
|---|
| 37 | obs::signal<void()> LanguageChange; | 
|---|
| 38 |  | 
|---|
| 39 | private: | 
|---|
| 40 | Strings(Preferences& pref, | 
|---|
| 41 | Extensions& exts); | 
|---|
| 42 |  | 
|---|
| 43 | void loadLanguage(const std::string& langId); | 
|---|
| 44 | void loadStringsFromDataDir(const std::string& langId); | 
|---|
| 45 | void loadStringsFromExtension(const std::string& langId); | 
|---|
| 46 | void loadStringsFromFile(const std::string& fn); | 
|---|
| 47 |  | 
|---|
| 48 | Preferences& m_pref; | 
|---|
| 49 | Extensions& m_exts; | 
|---|
| 50 | mutable std::unordered_map<std::string, std::string> m_strings; | 
|---|
| 51 | }; | 
|---|
| 52 |  | 
|---|
| 53 | } // namespace app | 
|---|
| 54 |  | 
|---|
| 55 | #endif | 
|---|
| 56 |  | 
|---|