forked from fnc12/Mitsoko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Language.cpp
62 lines (53 loc) · 1.56 KB
/
Language.cpp
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
//
// Language.cpp
// Jako
//
// Created by John Zakharov on 06.08.16.
// Copyright © 2016 Outlaw Studio. All rights reserved.
//
#include "Language.hpp"
std::string Viper::Language::_current;
std::mutex Viper::Language::languageOnceMutex;
const std::string& Viper::Language::current(){
if(!_current.length()){
languageOnceMutex.lock();
#ifdef __APPLE__
NS::String currentLanguage = NS::Bundle::mainBundle().preferredLocalizations()[0];
_current = currentLanguage.UTF8String();
#else
auto language = java::util::Locale::getDefault().getLanguage();
_current = language.c_str();
#endif
languageOnceMutex.unlock();
}
return _current;
}
void Viper::Language::setCurrent(const std::string &newValue){
_current=newValue;
}
std::string Viper::localizedString(const std::string &key,const std::string &lang){
if(lang.length()){
auto mapIt=R::localizedStrings().find(lang);
if(mapIt != R::localizedStrings().end()){
auto pIt=mapIt->second.find(key);
if(pIt != mapIt->second.end()){
return pIt->second;
}else{
return key;
}
}else{
return key;
}
}else{
return key;
}
}
std::string Viper::localizedString(const std::string &key){
return localizedString(key,Language::current());
}
std::string Viper::operator"" _ls (const char *s,size_t len){
return localizedString({s,len});
}
std::string Viper::Localizator::operator()(const std::string &s) const{
return localizedString(s);
}