Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 309284703
  • Loading branch information
Wenyu Zhang authored and material-automation committed Apr 30, 2020
1 parent 1920b96 commit 81bd1dd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
22 changes: 21 additions & 1 deletion components/TextFields/src/MDCMultilineTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
static NSString *const kClearButtonKey = @"MaterialTextFieldClearButtonAccessibilityLabel";
/** Table name within the bundle used for localizing accessibility values. */
static NSString *const kAccessibilityLocalizationStringsTableName = @"MaterialTextField";
// The Bundle for string resources.
static NSString *const kBundle = @"MaterialTextFields.bundle";

@interface MDCMultilineTextField () {
UIColor *_cursorColor;
Expand Down Expand Up @@ -129,7 +131,7 @@ - (void)commonMDCMultilineTextFieldInitialization {
// TODO: (#4331) This needs to be converted to the new text scheme.
self.font = [UIFont mdc_standardFontForMaterialTextStyle:MDCFontTextStyleBody1];
self.clearButton.tintColor = [UIColor colorWithWhite:0 alpha:[MDCTypography captionFontOpacity]];
NSBundle *bundle = [NSBundle bundleForClass:[MDCMultilineTextField class]];
NSBundle *bundle = [[self class] bundle];
NSString *accessibilityLabel =
[bundle localizedStringForKey:kClearButtonKey
value:@"Clear text"
Expand Down Expand Up @@ -830,4 +832,22 @@ - (void)mdc_setAdjustsFontForContentSizeCategory:(BOOL)adjusts {
[_fundament mdc_setAdjustsFontForContentSizeCategory:adjusts];
}

#pragma mark - Resource Bundle

+ (NSBundle *)bundle {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
bundle = [NSBundle bundleWithPath:[self bundlePathWithName:kBundle]];
});

return bundle;
}

+ (NSString *)bundlePathWithName:(NSString *)bundleName {
NSBundle *bundle = [NSBundle bundleForClass:[MDCMultilineTextField class]];
NSString *resourcePath = [(nil == bundle ? [NSBundle mainBundle] : bundle) resourcePath];
return [resourcePath stringByAppendingPathComponent:bundleName];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020-present the Material Components for iOS authors. 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 <XCTest/XCTest.h>
#import "MaterialTextFields.h"

@interface MultilineTextFieldLocalizationTests : XCTestCase

@end

@implementation MultilineTextFieldLocalizationTests

- (void)testAccessibilityLabelIsTranslated {
// Given
MDCMultilineTextField *field = [[MDCMultilineTextField alloc] init];
NSString *languageCode =
[NSLocale.preferredLanguages.firstObject componentsSeparatedByString:@"-"].firstObject;

// Then
if ([languageCode isEqualToString:@"ar"]) {
XCTAssertEqualObjects(field.clearButton.accessibilityLabel, @"محو النص");
} else {
XCTFail(@"Language %@ isn't supported by this localization test case", languageCode);
}
}

@end

0 comments on commit 81bd1dd

Please sign in to comment.