Skip to content

Commit

Permalink
feat: get stats for shared sims
Browse files Browse the repository at this point in the history
For #347.

Came out of phetsims/qa#869.
  • Loading branch information
liammulh committed Feb 8, 2023
1 parent 72e6c7e commit 968753b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/server/translationApi/getCategorizedStringKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ const getCategorizedStringKeys = async ( simName, simNames, stringKeysWithRepoNa
else if ( simNames.includes( repoName ) ) {
logger.verbose( `categorizing shared string key: ${stringKeyWithRepoName}` );
categorizedStringKeys.shared.push( stringKey );
categorizedStringKeys.sharedSims.push( repoName );
if ( !categorizedStringKeys.sharedSims.includes( repoName ) ) {
categorizedStringKeys.sharedSims.push( repoName );
}
}
else {
logger.verbose( `categorizing common string key: ${stringKeyWithRepoName}` );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import getLatestSimSha from '../getLatestSimSha.js';
import getSimHtml from '../getSimHtml.js';
import getSimUrl from '../getSimUrl.js';
import getStringKeysWithRepoName from '../getStringKeysWithRepoName.js';
import logger from '../logger.js';
import getCommonEnglishStringKeysAndValues from './getCommonEnglishStringKeysAndValues.js';
import getCommonTranslatedStringKeysAndValues from './getCommonTranslatedStringKeysAndValues.js';
import getSimSpecificEnglishStringKeysAndValues from './getSimSpecificEnglishStringKeysAndValues.js';
Expand Down Expand Up @@ -101,6 +102,51 @@ const getTranslationReportObject = async (
} ).length;
}

// If there are shared strings for this sim, we need to get the stats for those.
if ( categorizedStringKeys.shared.length > 0 ) {

translationReportObject.numSharedStrings = 0;
translationReportObject.numSharedTranslatedStrings = 0;

// It's possible a sim shares strings with multiple sims, hence the loop.
for ( const sharedSim of categorizedStringKeys.sharedSims ) {

// TODO: If there's a report object cached, use that.
// Get the English file.
const sharedSimUrl = getSimUrl( sharedSim );
const sharedSimHtml = await getSimHtml( sharedSimUrl );
const sharedStringKeysWithRepoName = Object.keys( getStringKeysWithRepoName( sharedSimHtml ) );
const sharedCategorizedStringKeys = await getCategorizedStringKeys( sharedSim, simNames, sharedStringKeysWithRepoName );
const latestSimSha = await getLatestSimSha( sharedSim );
logger.info( `getting shared sim-specific english string keys and values for ${sharedSim}` );
const sharedEnglishStringKeysAndValues = await getSimSpecificEnglishStringKeysAndValues(
sharedSim,
latestSimSha,
sharedCategorizedStringKeys,
sharedStringKeysWithRepoName
);
translationReportObject.numSharedStrings += Object
.values( sharedEnglishStringKeysAndValues )
.filter( value => value !== noLongerUsedFlag ).length;

// Get the translated file.
if ( wantsUntranslated === 'false' ) {
logger.info( `getting shared sim-specific translated string keys and values for ${sharedSim}` );
const sharedTranslatedStringKeysAndValues = await getSimSpecificTranslatedStringKeysAndValues(
sharedSim,
locale,
sharedCategorizedStringKeys
);
translationReportObject.numSharedTranslatedStrings += Object
.keys( sharedTranslatedStringKeysAndValues )
.filter( key => {
return sharedTranslatedStringKeysAndValues[ key ] !== ''
&& sharedEnglishStringKeysAndValues[ key ] !== noLongerUsedFlag;
} ).length;
}
}
}

return translationReportObject;
};

Expand Down

0 comments on commit 968753b

Please sign in to comment.