Skip to content

Commit

Permalink
Grunt update. Adding linebreak dependency for unicode-correct line br…
Browse files Browse the repository at this point in the history
…eak detection. Adding back directional marks into load-unbuilt-strings. Proper RichText line break handling. See phetsims/joist#843
  • Loading branch information
jonathanolson committed Aug 31, 2022
1 parent b80109e commit 4711345
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"../sherpa/lib/lodash-4.17.4.js",
"../sherpa/lib/FileSaver-b8054a2.js",
"../sherpa/lib/himalaya-1.1.0.js",
"../sherpa/lib/linebreak-1.1.0.js",
"../sherpa/lib/flatqueue-1.2.1.js",
"../sherpa/lib/he-1.1.1.js",
"../assert/js/assert.js",
Expand Down
20 changes: 19 additions & 1 deletion js/load-unbuilt-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
// Constructing the string map
window.phet.chipper.strings = {};

// Prefixes, ideally a better way of accessing localeInfo on startup would exist. We have localeInfo, however it's
// in the form of a module, and we can't use that at this point.
const rtlLocales = [ 'ae', 'ar', 'fa', 'iw', 'ur' ];

const localeQueryParam = new window.URLSearchParams( window.location.search ).get( 'locale' );
const localesQueryParam = new window.URLSearchParams( window.location.search ).get( 'locales' );

Expand All @@ -46,6 +50,13 @@
* @param {string} locale
*/
const processStringFile = ( stringObject, requirejsNamespace, locale ) => {
// See if we are in an RTL locale (lodash is unavailable at this point)
let isRTL = false;
rtlLocales.forEach( rtlLocale => {
if ( locale.startsWith( rtlLocale ) ) {
isRTL = true;
}
} );

const stringKeyPrefix = `${requirejsNamespace}/`;

Expand All @@ -56,7 +67,14 @@
const recurse = ( path, object ) => {
Object.keys( object ).forEach( key => {
if ( key === 'value' ) {
localeStringMap[ `${stringKeyPrefix}${path}` ] = object.value;
let value = object.value;

// Add directional marks
if ( value.length > 0 ) {
value = `${( isRTL ? '\u202b' : '\u202a' )}${value}\u202c`;
}

localeStringMap[ `${stringKeyPrefix}${path}` ] = value;
}
else if ( object[ key ] && typeof object[ key ] === 'object' ) {
recurse( `${path}${path.length ? '.' : ''}${key}`, object[ key ] );
Expand Down
15 changes: 15 additions & 0 deletions phet-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ declare var TWEEN: { update: ( dt: number ) => void };
declare var phetSplashScreen: { dispose: () => void };
declare var phetio: Record<string, IntentionalAny>;

// Typing for linebreaker-1.1.0.js preload
declare type LineBreakerBreak = {
position: number;
required: boolean;
};
declare type LineBreakerType = {
nextBreak(): LineBreakerBreak | null;

// We make it iterable
[ Symbol.iterator ](): Iterator<LineBreakerBreak, undefined>;
};
declare var LineBreaker: {
new ( str: string ): LineBreakerType;
};

declare var assertions: {
enableAssert: () => void;
};
Expand Down

0 comments on commit 4711345

Please sign in to comment.