1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00
OpenMW/components/l10n/manager.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.4 KiB
C++
Raw Normal View History

2022-10-02 20:38:37 +00:00
#ifndef COMPONENTS_L10N_MANAGER_H
#define COMPONENTS_L10N_MANAGER_H
2023-02-20 09:55:46 +00:00
#include <memory>
2022-10-02 20:38:37 +00:00
#include <components/l10n/messagebundles.hpp>
namespace VFS
{
class Manager;
}
namespace l10n
{
class Manager
{
public:
Manager(const VFS::Manager* vfs)
: mVFS(vfs)
{
}
void dropCache() { mCache.clear(); }
2023-06-13 07:48:40 +00:00
void setPreferredLocales(const std::vector<std::string>& locales, bool gmstHasPriority = true);
2022-10-02 20:38:37 +00:00
const std::vector<icu::Locale>& getPreferredLocales() const { return mPreferredLocales; }
2023-03-11 23:34:17 +00:00
void setGmstLoader(std::function<std::string(std::string_view)> fn) { mGmstLoader = std::move(fn); }
2022-10-02 20:38:37 +00:00
std::shared_ptr<const MessageBundles> getContext(
const std::string& contextName, const std::string& fallbackLocale = "en");
std::string getMessage(const std::string& contextName, std::string_view key)
{
return getContext(contextName)->formatMessage(key, {}, {});
}
2022-10-02 20:38:37 +00:00
private:
void readLangData(const std::string& name, MessageBundles& ctx, const icu::Locale& lang);
void updateContext(const std::string& name, MessageBundles& ctx);
const VFS::Manager* mVFS;
std::vector<icu::Locale> mPreferredLocales;
std::map<std::pair<std::string, std::string>, std::shared_ptr<MessageBundles>> mCache;
2023-03-11 23:34:17 +00:00
std::function<std::string(std::string_view)> mGmstLoader;
2022-10-02 20:38:37 +00:00
};
}
#endif // COMPONENTS_L10N_MANAGER_H