Skip to content

Commit

Permalink
Support dynamic locale for AtomIdentifier element name, #215
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 16, 2023
1 parent 193fa30 commit 085accd
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions js/common/view/ElementNameText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import { Color, Text, TextOptions } from '../../../../scenery/js/imports.js';
import buildANucleus from '../../buildANucleus.js';
import DerivedStringProperty from '../../../../axon/js/DerivedStringProperty.js';
import BuildANucleusStrings from '../../BuildANucleusStrings.js';
import AtomIdentifier from '../../../../shred/js/AtomIdentifier.js';
import AtomIdentifier, { nameTable } from '../../../../shred/js/AtomIdentifier.js';
import StringUtils from '../../../../phetcommon/js/util/StringUtils.js';
import BANConstants from '../BANConstants.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';

export type ElementNameTextOptions = TextOptions;

Expand All @@ -35,7 +35,7 @@ export default class ElementNameText extends Text {
maxWidth: BANConstants.ELEMENT_NAME_MAX_WIDTH
}, providedOptions );

const elementNameStringProperty = new DerivedStringProperty( [
const elementNameStringProperty = DerivedProperty.deriveAny( [
protonCountProperty,
neutronCountProperty,
nuclideExistsProperty,
Expand All @@ -47,9 +47,15 @@ export default class ElementNameText extends Text {
BuildANucleusStrings.doesNotFormStringProperty,
BuildANucleusStrings.zeroParticlesDoesNotFormPatternStringProperty,
BuildANucleusStrings.neutronLowercaseStringProperty,
BuildANucleusStrings.clusterOfNeutronsPatternStringProperty
], ( protonNumber, neutronNumber, doesNuclideExist ) => {
let name = AtomIdentifier.getName( protonNumber );
BuildANucleusStrings.clusterOfNeutronsPatternStringProperty,
...nameTable // when any name of any element changes, we should update here.
], () => {

const protonNumber = protonCountProperty.value;
const neutronNumber = neutronCountProperty.value;
const doesNuclideExist = nuclideExistsProperty.value;

let name = AtomIdentifier.getName( protonNumber ).value;
const massNumber = protonNumber + neutronNumber;

const massNumberString = massNumber.toString();
Expand Down

0 comments on commit 085accd

Please sign in to comment.