Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Grechuhin <i.grechuhin@gmail.com>2017-11-03 11:49:48 +0300
committerVlad Mihaylenko <vxmihaylenko@gmail.com>2017-11-03 15:01:55 +0300
commitcf352f93c089eec92989cecf3cc69d75a2104ed5 (patch)
tree284775f7e357fdf0370e4791d6256411585d0cc9
parent15ea0f828a98cdbf839fe399beb3ac38fb8b3c2e (diff)
[MAPSME-5899] [ios] Added input language retrieval functions.beta-1098
-rw-r--r--iphone/Maps/Categories/UIWindow+InputLanguage.swift15
-rw-r--r--iphone/Maps/Common/AppInfo.h2
-rw-r--r--iphone/Maps/Common/AppInfo.mm30
-rw-r--r--iphone/Maps/Maps.xcodeproj/project.pbxproj8
4 files changed, 45 insertions, 10 deletions
diff --git a/iphone/Maps/Categories/UIWindow+InputLanguage.swift b/iphone/Maps/Categories/UIWindow+InputLanguage.swift
new file mode 100644
index 0000000000..8782b2cbfb
--- /dev/null
+++ b/iphone/Maps/Categories/UIWindow+InputLanguage.swift
@@ -0,0 +1,15 @@
+extension UIWindow {
+ private func findFirstResponder(view: UIView) -> UIResponder? {
+ guard !view.isFirstResponder else { return view }
+ for subView in view.subviews {
+ if let responder = findFirstResponder(view: subView) {
+ return responder
+ }
+ }
+ return nil
+ }
+
+ @objc func firstResponder() -> UIResponder? {
+ return findFirstResponder(view: self)
+ }
+}
diff --git a/iphone/Maps/Common/AppInfo.h b/iphone/Maps/Common/AppInfo.h
index 72848aa0b6..6591a14efd 100644
--- a/iphone/Maps/Common/AppInfo.h
+++ b/iphone/Maps/Common/AppInfo.h
@@ -14,6 +14,8 @@ typedef NS_ENUM(NSInteger, MWMOpenGLDriver) {
@property(nonatomic, readonly) NSString * bundleVersion;
@property(nonatomic, readonly) NSString * buildNumber;
@property(nonatomic, readonly) NSUUID * advertisingId;
+@property(nonatomic, readonly) NSString * inputLanguage;
+@property(nonatomic, readonly) NSString * twoLetterInputLanguage;
@property(nonatomic, readonly) NSString * languageId;
@property(nonatomic, readonly) NSString * twoLetterLanguageId;
@property(nonatomic, readonly) NSDate * buildDate;
diff --git a/iphone/Maps/Common/AppInfo.mm b/iphone/Maps/Common/AppInfo.mm
index e85f62a940..b9fdb09001 100644
--- a/iphone/Maps/Common/AppInfo.mm
+++ b/iphone/Maps/Common/AppInfo.mm
@@ -3,7 +3,9 @@
#import <CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <sys/utsname.h>
+#import "LocaleTranslator.h"
#import "MWMCommon.h"
+#import "SwiftBridge.h"
#include "platform/settings.hpp"
@@ -79,7 +81,6 @@ NSDictionary * const kDeviceNamesWithMetalDriver = @{
@"iPhone9,3" : @"iPhone 7",
@"iPhone9,4" : @"iPhone 7 Plus"
};
-
} // namespace
@interface AppInfo ()
@@ -192,6 +193,23 @@ NSDictionary * const kDeviceNamesWithMetalDriver = @{
return _advertisingId;
}
+- (NSString *)inputLanguage
+{
+ auto window = UIApplication.sharedApplication.keyWindow;
+ auto firstResponder = [window firstResponder];
+ if (!firstResponder)
+ return self.languageId;
+ auto textInputMode = firstResponder.textInputMode;
+ if (!textInputMode)
+ return self.languageId;
+ return textInputMode.primaryLanguage;
+}
+
+- (NSString *)twoLetterInputLanguage
+{
+ return @(locale_translator::bcp47ToTwineLanguage(self.inputLanguage).c_str());
+}
+
- (NSString *)languageId
{
NSArray * languages = NSLocale.preferredLanguages;
@@ -200,15 +218,7 @@ NSDictionary * const kDeviceNamesWithMetalDriver = @{
- (NSString *)twoLetterLanguageId
{
- NSString * languageId = self.languageId;
- auto constexpr maxCodeLength = 2UL;
- auto const length = languageId.length;
- if (length > maxCodeLength)
- languageId = [languageId substringToIndex:maxCodeLength];
- else if (length < maxCodeLength)
- languageId = @"en";
-
- return languageId;
+ return @(locale_translator::bcp47ToTwineLanguage(self.languageId).c_str());
}
- (NSDate *)buildDate
diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj
index c2317eaba4..1cce1fcd72 100644
--- a/iphone/Maps/Maps.xcodeproj/project.pbxproj
+++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj
@@ -416,6 +416,9 @@
347BFA8F1F27909200E5531F /* MenuArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347BFA8E1F27909200E5531F /* MenuArea.swift */; };
347BFA901F27909200E5531F /* MenuArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347BFA8E1F27909200E5531F /* MenuArea.swift */; };
347BFA911F27909200E5531F /* MenuArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347BFA8E1F27909200E5531F /* MenuArea.swift */; };
+ 347E03991FAC5F1D00426032 /* UIWindow+InputLanguage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E03981FAC5F1D00426032 /* UIWindow+InputLanguage.swift */; };
+ 347E039A1FAC5F1D00426032 /* UIWindow+InputLanguage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E03981FAC5F1D00426032 /* UIWindow+InputLanguage.swift */; };
+ 347E039B1FAC5F1D00426032 /* UIWindow+InputLanguage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E03981FAC5F1D00426032 /* UIWindow+InputLanguage.swift */; };
347E1A881F1F5DD7002BF7A8 /* CianItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E1A871F1F5DD7002BF7A8 /* CianItemModel.swift */; };
347E1A891F1F5DD7002BF7A8 /* CianItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E1A871F1F5DD7002BF7A8 /* CianItemModel.swift */; };
347E1A8A1F1F5DD7002BF7A8 /* CianItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E1A871F1F5DD7002BF7A8 /* CianItemModel.swift */; };
@@ -2071,6 +2074,7 @@
347BFA931F28842300E5531F /* MWMNavigationDashboardObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MWMNavigationDashboardObserver.h; sourceTree = "<group>"; };
347D15C71F82362900E86251 /* GoogleSignIn.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GoogleSignIn.framework; path = GoogleSignIn/GoogleSignIn.framework; sourceTree = "<group>"; };
347D15C81F82362900E86251 /* GoogleSignInDependencies.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GoogleSignInDependencies.framework; path = GoogleSignIn/GoogleSignInDependencies.framework; sourceTree = "<group>"; };
+ 347E03981FAC5F1D00426032 /* UIWindow+InputLanguage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIWindow+InputLanguage.swift"; sourceTree = "<group>"; };
347E1A871F1F5DD7002BF7A8 /* CianItemModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CianItemModel.swift; sourceTree = "<group>"; };
347E1A8C1F1F71F1002BF7A8 /* PPCianCarouselCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PPCianCarouselCell.swift; sourceTree = "<group>"; };
347E1A901F1F72AD002BF7A8 /* PPCianCarouselCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PPCianCarouselCell.xib; sourceTree = "<group>"; };
@@ -3424,6 +3428,7 @@
349D1CE21E3F836900A878FD /* UIViewController+Hierarchy.swift */,
34F7422F1E0834F400AC1FD6 /* UIViewController+Navigation.h */,
34F742301E0834F400AC1FD6 /* UIViewController+Navigation.mm */,
+ 347E03981FAC5F1D00426032 /* UIWindow+InputLanguage.swift */,
);
path = Categories;
sourceTree = "<group>";
@@ -6032,6 +6037,7 @@
34926BE61EA4C2A700DCF14C /* SearchBanners.swift in Sources */,
34D4FA621E26572D003F53EF /* FirstLaunchController.swift in Sources */,
34C9BD041C6DB693000DC38D /* MWMViewController.mm in Sources */,
+ 347E03991FAC5F1D00426032 /* UIWindow+InputLanguage.swift in Sources */,
3404165B1E7C29AE00E2B6D6 /* PhotosInteractionAnimator.swift in Sources */,
340475701E081A4600C92850 /* MWMSettings.mm in Sources */,
34E50DDF1F6FCBA1008EED49 /* UGCAddReviewCell.swift in Sources */,
@@ -6393,6 +6399,7 @@
34E776271F14FE77003040B3 /* NavigationStreetNameView.swift in Sources */,
34926BE71EA4C2A700DCF14C /* SearchBanners.swift in Sources */,
34D3B02A1E389D05004100F9 /* MWMEditorAdditionalNameTableViewCell.mm in Sources */,
+ 347E039A1FAC5F1D00426032 /* UIWindow+InputLanguage.swift in Sources */,
340475711E081A4600C92850 /* MWMSettings.mm in Sources */,
3404165C1E7C29AE00E2B6D6 /* PhotosInteractionAnimator.swift in Sources */,
34E50DE01F6FCBA1008EED49 /* UGCAddReviewCell.swift in Sources */,
@@ -6754,6 +6761,7 @@
34D3B02B1E389D05004100F9 /* MWMEditorAdditionalNameTableViewCell.mm in Sources */,
34E776281F14FE77003040B3 /* NavigationStreetNameView.swift in Sources */,
34926BE81EA4C2A700DCF14C /* SearchBanners.swift in Sources */,
+ 347E039B1FAC5F1D00426032 /* UIWindow+InputLanguage.swift in Sources */,
3454D7C61E07F045004AF2AD /* UIButton+Orientation.mm in Sources */,
3404165D1E7C29AE00E2B6D6 /* PhotosInteractionAnimator.swift in Sources */,
34E50DE11F6FCBA1008EED49 /* UGCAddReviewCell.swift in Sources */,