diff --git a/js/i18n/localeProperty.ts b/js/i18n/localeProperty.ts index ee6cfa78..92e8bb3b 100644 --- a/js/i18n/localeProperty.ts +++ b/js/i18n/localeProperty.ts @@ -6,13 +6,15 @@ * @author Jonathan Olson */ -import Property from '../../../axon/js/Property.js'; +import Property, { PropertyOptions } from '../../../axon/js/Property.js'; import { ReadOnlyPropertyState } from '../../../axon/js/ReadOnlyProperty.js'; import StringUtils from '../../../phetcommon/js/util/StringUtils.js'; import { globalKeyStateTracker, KeyboardUtils } from '../../../scenery/js/imports.js'; import Tandem from '../../../tandem/js/Tandem.js'; import StringIO from '../../../tandem/js/types/StringIO.js'; import joist from '../joist.js'; +import optionize, { EmptySelfOptions } from '../../../phet-core/js/optionize.js'; +import StrictOmit from '../../../phet-core/js/types/StrictOmit.js'; // Hard coding a few locales here is better than relying on a generated output of the "ground truth" localeData in babel, // which could change at any time and cause a type error here (either on main or worse, in release branches). Also we @@ -32,9 +34,23 @@ const availableRuntimeLocales = ( Object.keys( phet.chipper.strings ) as Locale[ return lowerCaseA.localeCompare( lowerCaseB, 'en-US', { sensitivity: 'base' } ); } ); +type SelfOptions = EmptySelfOptions; +type LocalePropertyOptions = SelfOptions & StrictOmit, 'valueType' | 'phetioValueType'>; + export class LocaleProperty extends Property { + public readonly availableRuntimeLocales: Locale[] = availableRuntimeLocales; + public constructor( value: Locale, providedOptions?: LocalePropertyOptions ) { + + const options = optionize>()( { + valueType: 'string', + phetioValueType: StringIO + }, providedOptions ); + + super( value, options ); + } + // Override to provide grace and support for the full definition of allowed locales (aligned with the query parameter // schema). For example three letter values, and case insensitivity. See checkAndRemapLocale() for details. NOTE that // this will assert if the locale doesn't match the right format. @@ -62,9 +78,7 @@ export class LocaleProperty extends Property { const localeProperty = new LocaleProperty( phet.chipper.locale, { tandem: Tandem.GENERAL_MODEL.createTandem( 'localeProperty' ), - valueType: 'string', phetioFeatured: true, - phetioValueType: StringIO, phetioDocumentation: 'Specifies language currently displayed in the simulation' } );