Skip to content

Commit

Permalink
Fall back to non-localized string if no translation is available
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robhogan authored and facebook-github-bot committed Apr 19, 2022
1 parent 23b6240 commit 1819651
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions React/Fabric/RCTLocalizationProvider.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,21 @@ @implementation RCTLocalizationProvider

+ (NSString *)RCTLocalizedString:(NSString *)oldString withDescription:(NSString *)description
{
NSString *candidate = nil;

if (_delegate != nil) {
return [_delegate localizedString:oldString withDescription:description];
candidate = [_delegate localizedString:oldString withDescription:description];
}

if (candidate == nil && _languagePack != nil) {
candidate = _languagePack[oldString];
}

if (_languagePack != nil) {
return _languagePack[oldString];
if (candidate == nil) {
candidate = oldString;
}

return oldString;
return candidate;
}

@end

0 comments on commit 1819651

Please sign in to comment.