Skip to content

Commit

Permalink
Don't add excessive directional characters (moving the adding of them…
Browse files Browse the repository at this point in the history
… from lookup to initial file load). See #599
  • Loading branch information
jonathanolson committed Aug 8, 2017
1 parent 65b58c7 commit 64abdd4
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions js/requirejs-plugins/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ define( function( require ) {
* @param {???} headers
*/
function getWithCache( url, callback, errback, headers ) {
// Read the locale from a query parameter, if it is there, or use the fallback locale
var locale = phet.chipper.queryParameters.locale;
if ( !localeInfo[ locale ] ) {
onload.error( new Error( 'unsupported locale: ' + locale ) );
}
var isRTL = localeInfo[ locale ].direction === 'rtl';

// Check for cache hit
if ( cache[ url ] ) {
Expand All @@ -52,7 +58,11 @@ define( function( require ) {
else {
// Cache miss: load the file parse, enter into cache and return it
text.get( url, function( loadedText ) {
cache[ url ] = parse( loadedText );
var parsed = parse( loadedText );
for ( var stringKey in parsed ) {
parsed[ stringKey ].value = ChipperStringUtils.addDirectionalFormatting( parsed[ stringKey ].value, isRTL );
}
cache[ url ] = parsed;
callback( cache[ url ] );
}, errback, headers );
}
Expand Down Expand Up @@ -142,14 +152,7 @@ define( function( require ) {

// strings may be specified via the 'strings' query parameter, value is expected to be encoded to avoid URI-reserved characters
var queryParameterStrings = parse( phet.chipper.queryParameters.strings || '{}' );

// Read the locale from a query parameter, if it is there, or use the fallback locale
locale = phet.chipper.queryParameters.locale;
if ( !localeInfo[ locale ] ) {
onload.error( new Error( 'unsupported locale: ' + locale ) );
}
var isRTL = localeInfo[ locale ].direction === 'rtl';

var fallbackSpecificPath = repositoryPath + '/' + getFilenameForLocale( ChipperConstants.FALLBACK_LOCALE );
var localeSpecificPath = ( locale === ChipperConstants.FALLBACK_LOCALE ) ?
fallbackSpecificPath :
Expand All @@ -172,10 +175,6 @@ define( function( require ) {

// Now get the primary strings.
getWithCache( localeSpecificPath, function( parsed ) {
for ( var stringKey in parsed ) {
parsed[ stringKey ].value = ChipperStringUtils.addDirectionalFormatting( parsed[ stringKey ].value, isRTL );
}

// Combine the primary and fallback strings into one object hash.
var parsedStrings = _.extend( parsedFallbackStrings, parsed );
if ( parsedStrings[ key ] !== undefined ) {
Expand Down

0 comments on commit 64abdd4

Please sign in to comment.