-
Notifications
You must be signed in to change notification settings - Fork 806
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
Changes from 1 commit
efe8879
36021c6
645f392
ac31e7d
e1bad38
86f1a13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | ||
|
@@ -30,11 +28,11 @@ virtual void SetUp() { | |
NSString* _subDirectory = @"en.lproj"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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() { | ||
|
@@ -61,14 +57,15 @@ virtual void TearDown() { | |
} | ||
|
||
StrongId<NSString> _playground; | ||
StrongId<NSString> bundlePath; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
|
There was a problem hiding this comment.
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