mirror of
https://github.com/OpenEmu/OpenEmu-SDK.git
synced 2025-11-01 10:15:12 +00:00
Port OELocalizationHelper to Swift
This commit is contained in:
@@ -105,8 +105,7 @@
|
||||
C6772BD61710E29C00ED580A /* OEControlDescription.m in Sources */ = {isa = PBXBuildFile; fileRef = C6772BCF1710E29C00ED580A /* OEControlDescription.m */; };
|
||||
C6772BD71710E29C00ED580A /* OEDeviceDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = C6772BD01710E29C00ED580A /* OEDeviceDescription.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
C6772BD81710E29C00ED580A /* OEDeviceDescription.m in Sources */ = {isa = PBXBuildFile; fileRef = C6772BD11710E29C00ED580A /* OEDeviceDescription.m */; };
|
||||
C6772BDF1710E41C00ED580A /* OELocalizationHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = C6772BDD1710E41C00ED580A /* OELocalizationHelper.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
C6772BE01710E41C00ED580A /* OELocalizationHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = C6772BDE1710E41C00ED580A /* OELocalizationHelper.m */; };
|
||||
C6772BE01710E41C00ED580A /* OELocalizationHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6772BDE1710E41C00ED580A /* OELocalizationHelper.swift */; };
|
||||
C6772BE11710E72A00ED580A /* OpenEmuBase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6772A261710A4BA00ED580A /* OpenEmuBase.framework */; };
|
||||
C694EEC21C2A078B00DFD15C /* OEPropertyList.h in Headers */ = {isa = PBXBuildFile; fileRef = C694EEC11C2A065400DFD15C /* OEPropertyList.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
C694EEC61C2A0A7D00DFD15C /* OEHIDEvent_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = C694EEC51C2A0A7D00DFD15C /* OEHIDEvent_Internal.h */; };
|
||||
@@ -239,8 +238,7 @@
|
||||
C6772BCF1710E29C00ED580A /* OEControlDescription.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OEControlDescription.m; sourceTree = "<group>"; };
|
||||
C6772BD01710E29C00ED580A /* OEDeviceDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OEDeviceDescription.h; sourceTree = "<group>"; };
|
||||
C6772BD11710E29C00ED580A /* OEDeviceDescription.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OEDeviceDescription.m; sourceTree = "<group>"; };
|
||||
C6772BDD1710E41C00ED580A /* OELocalizationHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OELocalizationHelper.h; sourceTree = "<group>"; };
|
||||
C6772BDE1710E41C00ED580A /* OELocalizationHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OELocalizationHelper.m; sourceTree = "<group>"; };
|
||||
C6772BDE1710E41C00ED580A /* OELocalizationHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OELocalizationHelper.swift; sourceTree = "<group>"; };
|
||||
C694EEC11C2A065400DFD15C /* OEPropertyList.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OEPropertyList.h; sourceTree = "<group>"; };
|
||||
C694EEC51C2A0A7D00DFD15C /* OEHIDEvent_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OEHIDEvent_Internal.h; sourceTree = "<group>"; };
|
||||
C6A726811C059BF000E35961 /* OEBindingDescription.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OEBindingDescription.h; sourceTree = "<group>"; };
|
||||
@@ -486,8 +484,7 @@
|
||||
878203E921C4A09800C1C2C9 /* OEDreamcastGDI.m */,
|
||||
C6605B821D725B0D009C7E91 /* OEM3UFile.h */,
|
||||
C6605B831D725B0D009C7E91 /* OEM3UFile.m */,
|
||||
C6772BDD1710E41C00ED580A /* OELocalizationHelper.h */,
|
||||
C6772BDE1710E41C00ED580A /* OELocalizationHelper.m */,
|
||||
C6772BDE1710E41C00ED580A /* OELocalizationHelper.swift */,
|
||||
01AFC70A2364E327005EEB08 /* NSData+OESystem.h */,
|
||||
01AFC70B2364E327005EEB08 /* NSData+OESystem.m */,
|
||||
);
|
||||
@@ -543,7 +540,6 @@
|
||||
C6772BC21710E28900ED580A /* OEHIDEvent.h in Headers */,
|
||||
C6772B9A1710E25300ED580A /* OEKeyBindingDescription.h in Headers */,
|
||||
C6772B981710E25300ED580A /* OEKeyBindingGroupDescription.h in Headers */,
|
||||
C6772BDF1710E41C00ED580A /* OELocalizationHelper.h in Headers */,
|
||||
C6772B9E1710E25300ED580A /* OEPlayerBindings.h in Headers */,
|
||||
C694EEC61C2A0A7D00DFD15C /* OEHIDEvent_Internal.h in Headers */,
|
||||
C6A726831C059BF000E35961 /* OEBindingDescription.h in Headers */,
|
||||
@@ -754,7 +750,7 @@
|
||||
C6605B851D725B0D009C7E91 /* OEM3UFile.m in Sources */,
|
||||
C6772BD61710E29C00ED580A /* OEControlDescription.m in Sources */,
|
||||
C6772BD81710E29C00ED580A /* OEDeviceDescription.m in Sources */,
|
||||
C6772BE01710E41C00ED580A /* OELocalizationHelper.m in Sources */,
|
||||
C6772BE01710E41C00ED580A /* OELocalizationHelper.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1078,6 +1074,7 @@
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
@@ -1108,11 +1105,18 @@
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
INFOPLIST_FILE = "OpenEmuSystem/OpenEmuSystem-Info.plist";
|
||||
INSTALL_PATH = "@executable_path/../Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
"@loader_path/Frameworks",
|
||||
);
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "org.openemu.${PRODUCT_NAME:rfc1034identifier}";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = macosx;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
WRAPPER_EXTENSION = framework;
|
||||
};
|
||||
name = Debug;
|
||||
@@ -1123,6 +1127,7 @@
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
@@ -1147,10 +1152,16 @@
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
INFOPLIST_FILE = "OpenEmuSystem/OpenEmuSystem-Info.plist";
|
||||
INSTALL_PATH = "@executable_path/../Frameworks";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/../Frameworks",
|
||||
"@loader_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "org.openemu.${PRODUCT_NAME:rfc1034identifier}";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = macosx;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
WRAPPER_EXTENSION = framework;
|
||||
};
|
||||
name = Release;
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2011, OpenEmu Team
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the OpenEmu Team nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSInteger, OERegion) {
|
||||
OERegionNA NS_SWIFT_NAME(na),
|
||||
OERegionJAP NS_SWIFT_NAME(jpn),
|
||||
OERegionEU NS_SWIFT_NAME(eu),
|
||||
OERegionOther
|
||||
};
|
||||
|
||||
extern NSString *const OERegionKey;
|
||||
|
||||
@interface OELocalizationHelper : NSObject
|
||||
|
||||
@property(class, readonly) OELocalizationHelper *sharedHelper;
|
||||
|
||||
@property OERegion region;
|
||||
|
||||
@property(readonly) NSString *regionName;
|
||||
|
||||
@property(readonly) BOOL isRegionNA NS_SWIFT_UNAVAILABLE("Use 'region == .na' instead");
|
||||
@property(readonly) BOOL isRegionEU NS_SWIFT_UNAVAILABLE("Use 'region == .eu' instead");
|
||||
@property(readonly) BOOL isRegionJAP NS_SWIFT_UNAVAILABLE("Use 'region == .jpn' instead");
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2011, OpenEmu Team
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the OpenEmu Team nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#import "OELocalizationHelper.h"
|
||||
|
||||
NSString *const OERegionKey = @"region";
|
||||
|
||||
@interface OELocalizationHelper ()
|
||||
- (void)OE_updateRegion;
|
||||
@end
|
||||
|
||||
#define OERegionNALocales @[@""]
|
||||
|
||||
@implementation OELocalizationHelper
|
||||
@synthesize region;
|
||||
|
||||
static OELocalizationHelper *sharedHelper;
|
||||
|
||||
+ (OELocalizationHelper *)sharedHelper
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedHelper = [self new];
|
||||
});
|
||||
|
||||
return sharedHelper;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if(self = [super init])
|
||||
{
|
||||
[self OE_updateRegion];
|
||||
|
||||
[[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:OERegionKey options:0 context:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:OERegionKey];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
[self OE_updateRegion];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
- (BOOL)isRegionNA { return region == OERegionNA; }
|
||||
- (BOOL)isRegionEU { return region == OERegionEU; }
|
||||
- (BOOL)isRegionJAP { return region == OERegionJAP; }
|
||||
|
||||
- (NSString*)regionName
|
||||
{
|
||||
switch ([self region])
|
||||
{
|
||||
case OERegionEU:
|
||||
return NSLocalizedString(@"Europe", "");
|
||||
break;
|
||||
case OERegionNA:
|
||||
return NSLocalizedString(@"North America", "");
|
||||
break;
|
||||
case OERegionJAP:
|
||||
return NSLocalizedString(@"Japan", "");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NSLocalizedString(@"Other Region", "");
|
||||
}
|
||||
#pragma mark -
|
||||
#define OERegionCodesAfrica @[@"AO",@"BF",@"BI",@"BJ",@"BW",@"CD",@"CF",@"CG",@"CI",@"CM",@"CV",@"DJ",@"DZ",@"EG",@"EH",@"ER",@"ET",@"GA",@"GH",@"GM",@"GN",@"GQ",@"GW",@"KE",@"KM",@"LR",@"LS",@"LY",@"MA",@"MG",@"ML",@"MR",@"MU",@"MW",@"MZ",@"NA",@"NE",@"NG",@"RE",@"RW",@"SC",@"SD",@"SH",@"SL",@"SN",@"SO",@"SS",@"ST",@"SZ",@"TD",@"TG",@"TN",@"TZ",@"UG",@"YT",@"ZA",@"ZM",@"ZW"]
|
||||
#define OERegionCodesAntarctica @[@"AQ",@"BV",@"GS",@"HM",@"TF"]
|
||||
#define OERegionCodesAsia @[@"AE",@"AF",@"AM",@"AZ",@"BD",@"BH",@"BN",@"BT",@"CC",@"CN",@"CX",@"CY",@"GE",@"HK",@"ID",@"IL",@"IN",@"IO",@"IQ",@"IR",@"JO",@"JP",@"KG",@"KH",@"KP",@"KR",@"KW",@"KZ",@"LA",@"LB",@"LK",@"MM",@"MN",@"MO",@"MV",@"MY",@"NP",@"OM",@"PH",@"PK",@"PS",@"QA",@"SA",@"SG",@"SY",@"TH",@"TJ",@"TL",@"TM",@"TR",@"TW",@"UZ",@"VN",@"YE"]
|
||||
#define OERegionCodesEurope @[@"AD",@"AL",@"AT",@"AX",@"BA",@"BE",@"BG",@"BY",@"CH",@"CZ",@"DE",@"DK",@"EE",@"ES",@"FI",@"FO",@"FR",@"GB",@"GG",@"GI",@"GR",@"HR",@"HU",@"IE",@"IM",@"IS",@"IT",@"JE",@"LI",@"LT",@"LU",@"LV",@"MC",@"MD",@"ME",@"MK",@"MT",@"NL",@"NO",@"PL",@"PT",@"RO",@"RS",@"RU",@"SE",@"SI",@"SJ",@"SK",@"SM",@"UA",@"VA"]
|
||||
#define OERegionCodesNorthAmerica @[@"AG",@"AI",@"AW",@"BB",@"BL",@"BM",@"BQ",@"BS",@"BZ",@"CA",@"CR",@"CU",@"CW",@"DM",@"DO",@"GD",@"GL",@"GP",@"GT",@"HN",@"HT",@"JM",@"KN",@"KY",@"LC",@"MF",@"MQ",@"MS",@"MX",@"NI",@"PA",@"PM",@"PR",@"SV",@"SX",@"TC",@"TT",@"US",@"VC",@"VG",@"VI"]
|
||||
#define OERegionCodesSouthAmerica @[@"AR",@"BO",@"BR",@"CL",@"CO",@"EC",@"FK",@"GF",@"GY",@"PE",@"PY",@"SR",@"UY",@"VE"]
|
||||
#define OERegionCodesOceania @[@"AS",@"AU",@"CK",@"FJ",@"FM",@"GU",@"KI",@"MH",@"MP",@"NC",@"NF",@"NR",@"NU",@"NZ",@"PF",@"PG",@"PN",@"PW",@"SB",@"TK",@"TO",@"TV",@"UM",@"VU",@"WF",@"WS"]
|
||||
#pragma mark -
|
||||
#pragma mark Private Methods
|
||||
|
||||
- (void)OE_updateRegion
|
||||
{
|
||||
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
|
||||
if([standardUserDefaults valueForKey:OERegionKey])
|
||||
region = [[standardUserDefaults valueForKey:OERegionKey] intValue];
|
||||
else
|
||||
{
|
||||
NSLocale *locale = [NSLocale currentLocale];
|
||||
|
||||
NSString *countryCode = [locale objectForKey:NSLocaleCountryCode];
|
||||
|
||||
if([OERegionCodesEurope containsObject:countryCode])
|
||||
region = OERegionEU;
|
||||
else if([OERegionCodesNorthAmerica containsObject:countryCode])
|
||||
region = OERegionNA;
|
||||
else if([@[@"JP", @"HK", @"TW"] containsObject:countryCode])
|
||||
region = OERegionJAP;
|
||||
else
|
||||
region = OERegionOther;
|
||||
}
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,136 @@
|
||||
// Copyright (c) 2022, OpenEmu Team
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the OpenEmu Team nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY OpenEmu Team ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL OpenEmu Team BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc
|
||||
@objcMembers
|
||||
public class OELocalizationHelper: NSObject {
|
||||
|
||||
@objc public enum OERegion: Int {
|
||||
@objc(OERegionNA)
|
||||
case na = 0
|
||||
@objc(OERegionEU)
|
||||
case eu = 1
|
||||
@objc(OERegionJPN)
|
||||
case jpn = 2
|
||||
@objc(OERegionOther)
|
||||
case other = 3
|
||||
|
||||
public var name: String {
|
||||
switch self {
|
||||
case .eu:
|
||||
return NSLocalizedString("Europe", comment: "")
|
||||
case .na:
|
||||
return NSLocalizedString("North America", comment: "")
|
||||
case .jpn:
|
||||
return NSLocalizedString("Japan", comment: "")
|
||||
case .other:
|
||||
return NSLocalizedString("Other Region", comment: "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static let OERegionKey = "region"
|
||||
|
||||
@objc(sharedHelper)
|
||||
public static let shared = OELocalizationHelper()
|
||||
|
||||
public private(set) var region: OERegion = .other
|
||||
|
||||
private override init() {
|
||||
super.init()
|
||||
updateRegion()
|
||||
|
||||
UserDefaults.standard.addObserver(self, forKeyPath: Self.OERegionKey, options: [], context: nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
UserDefaults.standard.removeObserver(self, forKeyPath: Self.OERegionKey)
|
||||
}
|
||||
|
||||
override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
||||
updateRegion()
|
||||
}
|
||||
|
||||
private func updateRegion() {
|
||||
if let value = UserDefaults.standard.value(forKey: Self.OERegionKey) as? Int {
|
||||
region = OELocalizationHelper.OERegion(rawValue: value) ?? .other
|
||||
}
|
||||
else if let regionCode = Locale.current.regionCode {
|
||||
|
||||
if OERegionCodes.europe.contains(regionCode) {
|
||||
region = .eu
|
||||
}
|
||||
else if OERegionCodes.northAmerica.contains(regionCode) {
|
||||
region = .na
|
||||
}
|
||||
else if ["JP", "HK", "TW"].contains(regionCode) {
|
||||
region = .jpn
|
||||
}
|
||||
else {
|
||||
region = .other
|
||||
}
|
||||
}
|
||||
else {
|
||||
region = .other
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Region Codes
|
||||
|
||||
private enum OERegionCodes {
|
||||
static let africa = ["AO","BF","BI","BJ","BW","CD","CF","CG","CI","CM","CV","DJ","DZ","EG","EH","ER","ET","GA","GH","GM","GN","GQ","GW","KE","KM","LR","LS","LY","MA","MG","ML","MR","MU","MW","MZ","NA","NE","NG","RE","RW","SC","SD","SH","SL","SN","SO","SS","ST","SZ","TD","TG","TN","TZ","UG","YT","ZA","ZM","ZW"]
|
||||
static let antarctica = ["AQ","BV","GS","HM","TF"]
|
||||
static let asia = ["AE","AF","AM","AZ","BD","BH","BN","BT","CC","CN","CX","CY","GE","HK","ID","IL","IN","IO","IQ","IR","JO","JP","KG","KH","KP","KR","KW","KZ","LA","LB","LK","MM","MN","MO","MV","MY","NP","OM","PH","PK","PS","QA","SA","SG","SY","TH","TJ","TL","TM","TR","TW","UZ","VN","YE"]
|
||||
static let europe = ["AD","AL","AT","AX","BA","BE","BG","BY","CH","CZ","DE","DK","EE","ES","FI","FO","FR","GB","GG","GI","GR","HR","HU","IE","IM","IS","IT","JE","LI","LT","LU","LV","MC","MD","ME","MK","MT","NL","NO","PL","PT","RO","RS","RU","SE","SI","SJ","SK","SM","UA","VA"]
|
||||
static let northAmerica = ["AG","AI","AW","BB","BL","BM","BQ","BS","BZ","CA","CR","CU","CW","DM","DO","GD","GL","GP","GT","HN","HT","JM","KN","KY","LC","MF","MQ","MS","MX","NI","PA","PM","PR","SV","SX","TC","TT","US","VC","VG","VI"]
|
||||
static let southAmerica = ["AR","BO","BR","CL","CO","EC","FK","GF","GY","PE","PY","SR","UY","VE"]
|
||||
static let oceania = ["AS","AU","CK","FJ","FM","GU","KI","MH","MP","NC","NF","NR","NU","NZ","PF","PG","PN","PW","SB","TK","TO","TV","UM","VU","WF","WS"]
|
||||
}
|
||||
}
|
||||
|
||||
@objc public extension OELocalizationHelper {
|
||||
|
||||
var regionName: String {
|
||||
return region.name
|
||||
}
|
||||
|
||||
var isRegionEU: Bool {
|
||||
region == .eu
|
||||
}
|
||||
|
||||
var isRegionNA: Bool {
|
||||
region == .na
|
||||
}
|
||||
|
||||
var isRegionJPN: Bool {
|
||||
region == .jpn
|
||||
}
|
||||
|
||||
@available(*, deprecated, renamed: "isRegionJPN")
|
||||
var isRegionJAP: Bool {
|
||||
isRegionJPN
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,8 @@
|
||||
|
||||
#import "OEBindingDescription_Internal.h"
|
||||
#import "OEBindingsController.h"
|
||||
#import "OELocalizationHelper.h"
|
||||
#import "OESystemResponder.h"
|
||||
#import <OpenEmuSystem/OpenEmuSystem-Swift.h>
|
||||
|
||||
#define OEHIDAxisTypeString @"OEHIDAxisType"
|
||||
#define OEHIDHatSwitchTypeString @"OEHIDEventHatSwitchType"
|
||||
@@ -196,7 +196,7 @@ static NSMapTable<NSString *, OESystemController *> *_registeredSystemController
|
||||
{
|
||||
case OERegionEU : fileName = @"Controller-Preferences-EU"; break;
|
||||
case OERegionNA : fileName = @"Controller-Preferences-NA"; break;
|
||||
case OERegionJAP : fileName = @"Controller-Preferences-JAP"; break;
|
||||
case OERegionJPN : fileName = @"Controller-Preferences-JAP"; break;
|
||||
default : break;
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ static NSMapTable<NSString *, OESystemController *> *_registeredSystemController
|
||||
switch ([[OELocalizationHelper sharedHelper] region]) {
|
||||
case OERegionNA:
|
||||
return _regionalSystemNames[OERegionalizedSystemNamesRegionKeyNorthAmerica] ?: _systemName;
|
||||
case OERegionJAP:
|
||||
case OERegionJPN:
|
||||
return _regionalSystemNames[OERegionalizedSystemNamesRegionKeyJapan] ?: _systemName;
|
||||
case OERegionEU:
|
||||
return _regionalSystemNames[OERegionalizedSystemNamesRegionKeyEurope] ?: _systemName;
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#import <OpenEmuSystem/OEHIDEvent.h>
|
||||
#import <OpenEmuSystem/OEKeyBindingDescription.h>
|
||||
#import <OpenEmuSystem/OEKeyBindingGroupDescription.h>
|
||||
#import <OpenEmuSystem/OELocalizationHelper.h>
|
||||
#import <OpenEmuSystem/OEPlayerBindings.h>
|
||||
#import <OpenEmuSystem/OESystemBindings.h>
|
||||
#import <OpenEmuSystem/OESystemController.h>
|
||||
|
||||
Reference in New Issue
Block a user