This repository has been archived by the owner on Oct 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial import of Bidi utility functions.
- Loading branch information
ianegordon
committed
Jul 30, 2018
1 parent
f71a090
commit 340899b
Showing
19 changed files
with
753 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ples/Flags/MDFInternationalizationExample/Assets.xcassets/BidiIcon.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "baseline_compare_arrows_black_36pt_1x.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "baseline_compare_arrows_black_36pt_2x.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "baseline_compare_arrows_black_36pt_3x.png", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+178 Bytes
...ple/Assets.xcassets/BidiIcon.imageset/baseline_compare_arrows_black_36pt_1x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+234 Bytes
...ple/Assets.xcassets/BidiIcon.imageset/baseline_compare_arrows_black_36pt_2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+341 Bytes
...ple/Assets.xcassets/BidiIcon.imageset/baseline_compare_arrows_black_36pt_3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 109 additions & 10 deletions
119
Examples/Flags/MDFInternationalizationExample/Base.lproj/Main.storyboard
Large diffs are not rendered by default.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
Examples/Flags/MDFInternationalizationExample/BidirectionalViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2018-present Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface BidirectionalViewController : UIViewController | ||
|
||
@end |
77 changes: 77 additions & 0 deletions
77
Examples/Flags/MDFInternationalizationExample/BidirectionalViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
Copyright 2018-present Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import "BidirectionalViewController.h" | ||
|
||
|
||
static NSString *kMDFLTREmbedding = @"\u202a"; // left-to-right embedding | ||
static NSString *kMDFRTLEmbedding = @"\u202b"; // right-to-left embedding | ||
static NSString *kMDFBidiPopEmbedding = @"\u202c"; // pop directional embedding | ||
|
||
static NSString *kMDFLTRMark = @"\u200e"; // left-to-right mark | ||
static NSString *kMDFRTLMark = @"\u200f"; // right-to-left mark | ||
|
||
// The following only work on iOS 10+ | ||
static NSString *kMDFLTRIsolate = @"\u2066"; // left-to-right isolate | ||
static NSString *kMDFRTLIsolate = @"\u2067"; // right-to-left isolate | ||
static NSString *kMDFFirstStrongIsolate = @"\u2068"; // first strong isolate | ||
static NSString *kMDFPopIsolate = @"\u2069"; // pop directional isolate | ||
|
||
|
||
@interface BidirectionalViewController () | ||
|
||
@property (weak, nonatomic) IBOutlet UILabel *labelOne; | ||
@property (weak, nonatomic) IBOutlet UILabel *labelTwo; | ||
@property (weak, nonatomic) IBOutlet UILabel *labelThree; | ||
@property (weak, nonatomic) IBOutlet UILabel *labelFour; | ||
|
||
@end | ||
|
||
@implementation BidirectionalViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
// Do any additional setup after loading the view. | ||
// The following lines will display a (: if the markers are supported, ): if not. | ||
self.labelOne.text = | ||
[NSString stringWithFormat:@"Bidi Isolate supported %@)%@:", kMDFRTLIsolate, kMDFPopIsolate]; | ||
self.labelTwo.text = | ||
[NSString stringWithFormat:@"Bidi Embed supported %@)%@:", kMDFRTLEmbedding, kMDFBidiPopEmbedding]; | ||
// self.labelThree.text = @"1st a-\u2068.)\u200f\u2069-b"; | ||
// self.labelFour.text = @"1st a-\u2068\u200f.)\u2069-b"; | ||
// self.labelFour.text = @"الو" // Hello | ||
NSString *three = [NSString stringWithFormat:@"Read %@15 books%@ EOL", kMDFFirstStrongIsolate, kMDFPopIsolate]; | ||
self.labelThree.text = three; | ||
NSString *four = [NSString stringWithFormat:@"Read %@15 كتاب%@ EOL", kMDFFirstStrongIsolate, kMDFPopIsolate]; | ||
self.labelFour.text = four; | ||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
[super didReceiveMemoryWarning]; | ||
// Dispose of any resources that can be recreated. | ||
} | ||
|
||
/* | ||
#pragma mark - Navigation | ||
// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | ||
// Get the new view controller using [segue destinationViewController]. | ||
// Pass the selected object to the new view controller. | ||
} | ||
*/ | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2018-present Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSLocale (MaterialRTL) | ||
|
||
/** | ||
Is the direction of the current locale's default language Left-To-Right? | ||
@return YES if the language is LTR, NO if the language is any other direction. | ||
*/ | ||
+ (BOOL)mdf_isDefaultLanguageLTR; | ||
|
||
/** | ||
Is the direction of the current locale's default language Right-To-Left? | ||
@return YES if the language is RTL, NO if the language is any other direction. | ||
*/ | ||
+ (BOOL)mdf_isDefaultLanguageRTL; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright 2018-present Google Inc. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#import "NSLocale+MaterialRTL.h" | ||
|
||
@implementation NSLocale (MaterialRTL) | ||
|
||
+ (BOOL)mdf_isDefaultLanguageLTR { | ||
NSString *languageCode = [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]; | ||
NSLocaleLanguageDirection characterDirection = | ||
[NSLocale characterDirectionForLanguage:languageCode]; | ||
BOOL localeLanguageDirectionIsLTR = (characterDirection == NSLocaleLanguageDirectionLeftToRight); | ||
return localeLanguageDirectionIsLTR; | ||
} | ||
|
||
+ (BOOL)mdf_isDefaultLanguageRTL { | ||
NSString *languageCode = [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]; | ||
NSLocaleLanguageDirection characterDirection = | ||
[NSLocale characterDirectionForLanguage:languageCode]; | ||
BOOL localeLanguageDirectionIsRTL = (characterDirection == NSLocaleLanguageDirectionRightToLeft); | ||
return localeLanguageDirectionIsRTL; | ||
} | ||
|
||
@end | ||
|
Oops, something went wrong.