Skip to content

Commit

Permalink
Auto register and unregister LocalizedString instances, see #1302
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Aug 21, 2022
1 parent 510f753 commit 47b6c79
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 5 additions & 0 deletions js/LocalizedString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Tandem from '../../tandem/js/Tandem.js';
import StringIO from '../../tandem/js/types/StringIO.js';
import chipper from './chipper.js';
import TProperty from '../../axon/js/TProperty.js';
import { localizedStrings } from './getStringModule.js';
import arrayRemove from '../../phet-core/js/arrayRemove.js';

// constants
const FALLBACK_LOCALE = 'en';
Expand Down Expand Up @@ -56,6 +58,8 @@ class LocalizedString {
phetioState: false,
tandem: tandem
} );

localizedStrings.push( this );
}

/**
Expand Down Expand Up @@ -197,6 +201,7 @@ class LocalizedString {
localeOrderProperty.unlink( this.localeOrderListener );

this.property.dispose();
arrayRemove( localizedStrings, this );
}
}

Expand Down
1 change: 0 additions & 1 deletion js/getStringModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ const getStringModule = ( requirejsNamespace: string ): object => {

const localizedString = new LocalizedString( phet.chipper.strings[ FALLBACK_LOCALE ][ stringKey ], tandem );
localizedStringMap[ stringKey ] = localizedString;
localizedStrings.push( localizedString );

// Push up the translated values
Object.keys( phet.chipper.strings ).forEach( locale => {
Expand Down

0 comments on commit 47b6c79

Please sign in to comment.