From 13d764911abf8ba0e8e39422a27f4c02b6ef28fd Mon Sep 17 00:00:00 2001 From: zepumph Date: Mon, 30 Sep 2019 13:12:38 -0800 Subject: [PATCH] don't add directional formatting to a11y strings, https://github.com/phetsims/chipper/issues/798 --- js/common/ChipperStringUtils.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/js/common/ChipperStringUtils.js b/js/common/ChipperStringUtils.js index af606a8f9..889e4e9cd 100644 --- a/js/common/ChipperStringUtils.js +++ b/js/common/ChipperStringUtils.js @@ -14,6 +14,7 @@ // What divides the repo prefix from the rest of the string key, like `FRICTION/friction.title` const NAMESPACE_PREFIX_DIVIDER = '/'; + const A11Y_MARKER = 'a11y.'; const ChipperStringUtils = { @@ -127,7 +128,11 @@ // remove leading/trailing whitespace, see chipper#619. Do this before addDirectionalFormatting stringObject.value = stringObject.value.trim(); - stringObject.value = ChipperStringUtils.addDirectionalFormatting( stringObject.value, isRTL ); + + // A11Y can't support i18n with this conditional in, this is more of a workaround, see https://github.com/phetsims/chipper/issues/798 + if ( !ChipperStringUtils.isA11yStringKey( key ) ) { + stringObject.value = ChipperStringUtils.addDirectionalFormatting( stringObject.value, isRTL ); + } } ); }, @@ -164,6 +169,15 @@ return null; }, + /** + * @public + * @param {string} key - without "string!REPO" at the beginning, just the actual "string key" + * @returns {boolean} + */ + isA11yStringKey( key ) { + return key.indexOf( ChipperStringUtils.A11Y_MARKER ) === 0; + }, + /** * Call a function on each object with a value attribute in an object tree. * @param {Object.} map - string map, like a loaded JSON strings file