Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NSLocalizedString and Add Localization Tests #2824

Merged
merged 6 commits into from
Dec 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Frameworks/CoreFoundation/PlugIn.subproj/CFBundle_Locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,6 @@ static CFStringRef _CFBundleCopyLanguageFoundInLocalizations(CFArrayRef localiza
// WINOBJC: Helper functions for workaround in _CFBundleCreateMutableArrayOfFallbackLanguages
static CFStringRef _copyStringTruncated(CFStringRef localization, CFRange cutoff) {
return CFStringCreateWithSubstring(NULL, localization, CFRangeMake(0, cutoff.location));
//CFMutableStringRef truncatedString = CFStringCreateMutableCopy(NULL, 0, localization);
//CFStringDelete(truncatedString, CFRangeMake(cutoff.location, CFStringGetLength(truncatedString) - cutoff.location));
//return truncatedString;
}

static CFStringRef _copyStringWithUnderscores(CFStringRef localization) {
Expand Down
1 change: 1 addition & 0 deletions samples/WOCCatalog/WOCCatalog/LocalizationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ @implementation LocalizationViewController {
UILabel* _pasteTextLabel;
}
- (void)viewDidLoad {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you may need [super viewDidLoad] here for completeness' sake

[super viewDidLoad];
self.tableView.allowsSelection = YES;
}

Expand Down
13 changes: 5 additions & 8 deletions tests/UnitTests/Foundation/WindowsOnly/BundleInternalTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#import <Foundation/Foundation.h>
#import <objc/encoding.h>

static NSString* _bundleName = @"MyBundle.bundle";

class NSBundleLocalization : public ::testing::Test {
public:
explicit NSBundleLocalization() : ::testing::Test() {
Expand All @@ -30,11 +28,11 @@ virtual void SetUp() {
NSString* _subDirectory = @"en.lproj";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? you're only testing looking strings up in the single lproj that exists, which usually matches the system locale.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point was to always find a localization we have. Since we know we can use English as a fallback the test doesn't care about what locale or language settings the machine has. This way we can ensure we're testing the localization changes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by testing the base localization, we aren't testing anything related to 1. localization or 2. localization changes though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, we're certainly testing the NSLocalizedString path. Grabbing a particular locale is not the goal here, nor is that something I think we can rely on with a unit test. The system can only have one locale setting, so it doesn't seem to matter to me which locale that is. Since English is a known fallback is that not acceptable?

NSString* localizationResourceName = @"Localizable.strings";
// Create a unique test directory
NSString* tempDir = [[@"./tmp_TestFoundation" stringByAppendingPathComponent:[NSUUID UUID].UUIDString] stringByAppendingPathComponent:@"/"];
NSString* bundlePath = [tempDir stringByAppendingPathComponent:_bundleName];
_playground = [@"./tmp_TestFoundation" stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
bundlePath = [_playground stringByAppendingPathComponent:@"MyBundle.bundle"];
NSError* error = nil;

NSString* localizationPath = [NSString stringWithFormat:@"%@/%@", bundlePath, _subDirectory];
NSString* localizationPath = [NSString stringWithFormat:@"%@/%@", bundlePath.get(), _subDirectory];
[[NSFileManager defaultManager] createDirectoryAtPath:localizationPath
withIntermediateDirectories:true
attributes:nil
Expand All @@ -48,8 +46,6 @@ virtual void SetUp() {
// As translated by Bing translate using unicode escapes to properly write to file
NSString* localization = @"\"Hello World\" = \"Hallo Welt\";\n\"Coding\" = \"\u7f16\u7801\";";
[localization writeToFile:filepath atomically:YES encoding:NSUnicodeStringEncoding error:&error];

_playground = tempDir;
}

virtual void TearDown() {
Expand All @@ -61,14 +57,15 @@ virtual void TearDown() {
}

StrongId<NSString> _playground;
StrongId<NSString> bundlePath;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_

};

TEST_F(NSBundleLocalization, LocalizedString) {
if (!_playground) {
ASSERT_TRUE_MSG(false, @"Unable to create bundle resources");
}

NSBundle* bundle = [NSBundle bundleWithPath:[_playground stringByAppendingPathComponent:_bundleName]];
NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
ASSERT_OBJCNE(bundle, nil);

NSString* helloWorld = @"Hello World";
Expand Down