-
-
Notifications
You must be signed in to change notification settings - Fork 997
/
Copy pathlocalization.mm
47 lines (38 loc) · 1.35 KB
/
localization.mm
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
#include "platform/localization.hpp"
#include <algorithm>
#import <Foundation/Foundation.h>
namespace platform
{
std::string GetLocalizedTypeName(std::string const & type)
{
auto key = "type." + type;
std::replace(key.begin(), key.end(), '-', '.');
std::replace(key.begin(), key.end(), ':', '_');
return [NSLocalizedString(@(key.c_str()), @"") UTF8String];
}
std::string GetLocalizedBrandName(std::string const & brand)
{
auto const key = "brand." + brand;
return [NSLocalizedStringWithDefaultValue(@(key.c_str()), nil, NSBundle.mainBundle, @(brand.c_str()), @"") UTF8String];
}
std::string GetLocalizedString(std::string const & key)
{
return [NSLocalizedString(@(key.c_str()), @"") UTF8String];
}
std::string GetCurrencySymbol(std::string const & currencyCode)
{
NSLocale * locale = [NSLocale currentLocale];
NSString * symbol = [locale displayNameForKey:NSLocaleCurrencySymbol
value:@(currencyCode.c_str())];
if (!symbol)
return currencyCode;
return [symbol UTF8String];
}
std::string GetLocalizedMyPositionBookmarkName()
{
NSDate * now = [NSDate date];
return [NSDateFormatter localizedStringFromDate:now
dateStyle:NSDateFormatterLongStyle
timeStyle:NSDateFormatterShortStyle].UTF8String;
}
} // namespace platform