Skip to content

Commit 0e99b19

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
RCTLocalizedString: Replace usages of AccessibilityResources (#37680)
Summary: Pull Request resolved: #37680 Changelog: [iOS][Fixed] - Localize Voiceover strings in Paper ## Stack React Native on iOS adds strings to Voiceover interactions to supply more information to users . Internally, and out-of-the-box externally, these are today always announced in English instead of being localized. This stack adds a limited new internal API, `RCTLocalizedString(string, description)` to allow auto-translated strings which are consumed by both Meta and OSS. Reviewed By: cipolleschi Differential Revision: D46415273 fbshipit-source-id: 4174e38cef4eee251fa2d59e10763cde8e8681ad
1 parent f83ca12 commit 0e99b19

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

packages/react-native/React/Views/RCTView.m

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import "RCTBorderCurve.h"
1515
#import "RCTBorderDrawing.h"
1616
#import "RCTI18nUtil.h"
17+
#import "RCTLocalizedString.h"
1718
#import "RCTLog.h"
1819
#import "RCTViewUtils.h"
1920
#import "UIView+React.h"
@@ -282,41 +283,44 @@ - (NSString *)accessibilityValue
282283
static NSDictionary<NSString *, NSString *> *rolesAndStatesDescription = nil;
283284

284285
dispatch_once(&onceToken, ^{
285-
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"AccessibilityResources" ofType:@"bundle"];
286-
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
287-
288-
if (bundle) {
289-
NSURL *url = [bundle URLForResource:@"Localizable" withExtension:@"strings"];
290-
rolesAndStatesDescription = [NSDictionary dictionaryWithContentsOfURL:url error:nil];
291-
}
292-
if (rolesAndStatesDescription == nil) {
293-
// Falling back to hardcoded English list.
294-
NSLog(@"Cannot load localized accessibility strings.");
295-
rolesAndStatesDescription = @{
296-
@"alert" : @"alert",
297-
@"checkbox" : @"checkbox",
298-
@"combobox" : @"combo box",
299-
@"menu" : @"menu",
300-
@"menubar" : @"menu bar",
301-
@"menuitem" : @"menu item",
302-
@"progressbar" : @"progress bar",
303-
@"radio" : @"radio button",
304-
@"radiogroup" : @"radio group",
305-
@"scrollbar" : @"scroll bar",
306-
@"spinbutton" : @"spin button",
307-
@"switch" : @"switch",
308-
@"tab" : @"tab",
309-
@"tablist" : @"tab list",
310-
@"timer" : @"timer",
311-
@"toolbar" : @"tool bar",
312-
@"checked" : @"checked",
313-
@"unchecked" : @"unchecked",
314-
@"busy" : @"busy",
315-
@"expanded" : @"expanded",
316-
@"collapsed" : @"collapsed",
317-
@"mixed" : @"mixed",
318-
};
319-
}
286+
rolesAndStatesDescription = @{
287+
@"alert" : RCTLocalizedString("alert", "important, and usually time-sensitive, information"),
288+
@"busy" : RCTLocalizedString("busy", "an element currently being updated or modified"),
289+
@"checkbox" : RCTLocalizedString("checkbox", "checkable interactive control"),
290+
@"combobox" : RCTLocalizedString(
291+
"combo box",
292+
"input that controls another element that can pop up to help the user set the value of that input"),
293+
@"menu" : RCTLocalizedString("menu", "offers a list of choices to the user"),
294+
@"menubar" : RCTLocalizedString(
295+
"menu bar", "presentation of menu that usually remains visible and is usually presented horizontally"),
296+
@"menuitem" : RCTLocalizedString("menu item", "an option in a set of choices contained by a menu or menubar"),
297+
@"progressbar" :
298+
RCTLocalizedString("progress bar", "displays the progress status for tasks that take a long time"),
299+
@"radio" : RCTLocalizedString(
300+
"radio button",
301+
"a checkable input that when associated with other radio buttons, only one of which can be checked at a time"),
302+
@"radiogroup" : RCTLocalizedString("radio group", "a group of radio buttons"),
303+
@"scrollbar" : RCTLocalizedString("scroll bar", "controls the scrolling of content within a viewing area"),
304+
@"spinbutton" : RCTLocalizedString(
305+
"spin button", "defines a type of range that expects the user to select a value from among discrete choices"),
306+
@"switch" : RCTLocalizedString("switch", "represents the states 'on' and 'off'"),
307+
@"tab" : RCTLocalizedString("tab", "an interactive element inside a tablist"),
308+
@"tablist" : RCTLocalizedString("tab list", "container for a set of tabs"),
309+
@"timer" : RCTLocalizedString(
310+
"timer",
311+
"a numerical counter listing the amount of elapsed time from a starting point or the remaining time until an end point"),
312+
@"toolbar" : RCTLocalizedString(
313+
"tool bar",
314+
"a collection of commonly used function buttons or controls represented in a compact visual form"),
315+
@"checked" : RCTLocalizedString("checked", "a checkbox, radio button, or other widget which is checked"),
316+
@"unchecked" : RCTLocalizedString("unchecked", "a checkbox, radio button, or other widget which is unchecked"),
317+
@"expanded" :
318+
RCTLocalizedString("expanded", "a menu, dialog, accordian panel, or other widget which is expanded"),
319+
@"collapsed" :
320+
RCTLocalizedString("collapsed", "a menu, dialog, accordian panel, or other widget which is collapsed"),
321+
@"mixed" :
322+
RCTLocalizedString("mixed", "a checkbox, radio button, or other widget which is both checked and unchecked"),
323+
};
320324
});
321325

322326
// Handle Switch.

0 commit comments

Comments
 (0)