Skip to content

Instantly share code, notes, and snippets.

@senfi
Last active January 18, 2016 09:37
Show Gist options
  • Save senfi/462bf35a1dd74393a8f8 to your computer and use it in GitHub Desktop.
Save senfi/462bf35a1dd74393a8f8 to your computer and use it in GitHub Desktop.
Workaround: problem with language in snapshotter
In your test file
- (NSString*)localizedString:(NSString *)key
{
NSString *language = _snapshotter._deviceLanguage;
NSString *translation = nil;
if(language)
{
language = [language stringByReplacingCharactersInRange:NSMakeRange(2, language.length-2) withString:@""];
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:language ofType:@"lproj"];
NSBundle *bundlelocalized = [NSBundle bundleWithPath:path];
translation = [bundlelocalized localizedStringForKey:key value:@"" table:nil];;
}
return translation;
}
In your Snapshot Helper
- (void)setLanguage
{
NSString* path = @"/tmp/language.txt";
NSError* error;
NSString* locale = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
_locale = [NSLocale localeWithLocaleIdentifier:locale];
if (error)
{
NSLog(@"❌ %s could not detect language. Falling back to device locale. %@", __PRETTY_FUNCTION__, error);
_locale = [NSLocale currentLocale];
locale = [_locale objectForKey:NSLocaleIdentifier];
}
if ( _locale
&& locale)
{
NSUInteger idx = 2;
if (locale.length < idx)
{
idx = locale.length;
}
_deviceLanguage = [locale substringToIndex:idx];
_app.launchArguments = [_app.launchArguments arrayByAddingObjectsFromArray:@[@"-AppleLanguages",[NSString stringWithFormat:@"(%@)", _deviceLanguage],@"-AppleLocale",locale, @"-ui_testing"]];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment