Skip to content

Commit 1819651

Browse files
robhoganfacebook-github-bot
authored andcommitted
Fall back to non-localized string if no translation is available
Summary: We've seen a couple of `EXC_BAD_ACCESS` crashes in [`RCTParagraphComponentAccessibilityProvider.mm:L125`](https://github.com/facebook/react-native/blob/52d8a797e7a6be3fa472f323ceca4814a28ef596/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentAccessibilityProvider.mm#L125), most likely explained by [RCTLocalizationProvider RCTLocalizedString] returning nil, which will happen in the case that a language pack has no entry for the input string. This is a small defensive change to fall back to the input if there's no better alternative. Changelog: [iOS][Fixed] - `RCTLocalizationProvider` Fall back to input when no localization is available Reviewed By: luluonet Differential Revision: D35583786 fbshipit-source-id: e8ae6ff61518e105301e7e51f5d8f43290fb20bf
1 parent 23b6240 commit 1819651

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

React/Fabric/RCTLocalizationProvider.mm

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,21 @@ @implementation RCTLocalizationProvider
2626

2727
+ (NSString *)RCTLocalizedString:(NSString *)oldString withDescription:(NSString *)description
2828
{
29+
NSString *candidate = nil;
30+
2931
if (_delegate != nil) {
30-
return [_delegate localizedString:oldString withDescription:description];
32+
candidate = [_delegate localizedString:oldString withDescription:description];
33+
}
34+
35+
if (candidate == nil && _languagePack != nil) {
36+
candidate = _languagePack[oldString];
3137
}
3238

33-
if (_languagePack != nil) {
34-
return _languagePack[oldString];
39+
if (candidate == nil) {
40+
candidate = oldString;
3541
}
3642

37-
return oldString;
43+
return candidate;
3844
}
3945

4046
@end

0 commit comments

Comments
 (0)