Closed pixelzoom closed 9 years ago
Also as part of the script: (1) move English string file to top-level of repo directory (2) reformat values in English string file to be object (vs strings)
Also modify string plug-in accordingly.
Was a bit trickier, since many files weren't valid JSON (non-space whitespace in strings, commas and brackets where they shouldn't be or missing). Should be good to go.
Feel free to review.
If the files were not valid JSON, that indicates a problem with PropertiesToJSON. Since we will continue to use that to migrate Java translations, it should be fixed. See https://github.com/phetsims/chipper/issues/131.
@jonathanolson I don't see any new script in chipper. And it would be really handy to have that script, because you missed hookes-law, which I'm actively working on. Did you have all active-repos checked out when you ran the script?
I manually reformatted and relocated hookes-law-lab-strings_en.json.
I don't believe it's too safe for reuse (does 'git rm'), so I don't want to check it in, but:
var fs = require( 'fs' );
var child_process = require( 'child_process' );
var repos = [ 'acid-base-solutions', 'area-builder', 'arithmetic', 'atomic-interactions', 'balancing-act', 'balancing-chemical-equations', 'balloons-and-static-electricity', 'beaker', 'beers-law-lab', 'bending-light', 'blackbody-spectrum', 'blast', 'build-a-molecule', 'build-an-atom', 'capacitor-lab', 'chains', 'charges-and-fields', 'circuit-construction-kit-basics', 'color-vision', 'concentration', 'curve-fitting', 'energy-forms-and-changes', 'energy-skate-park-basics', 'energy-skate-park', 'estimation', 'example-sim', 'faradays-law', 'fluid-pressure-and-flow', 'forces-and-motion-basics', 'fraction-comparison', 'fraction-matcher', 'friction', 'function-builder', 'gene-expression-basics', 'graphing-lines', 'graphing-quadratics', 'gravity-and-orbits', 'gravity-force-lab', 'isotopes-and-atomic-mass', 'john-travoltage', 'joist', 'least-squares-regression', 'masses-and-springs', 'molarity', 'molecule-polarity', 'molecule-shapes-basics', 'molecule-shapes', 'molecules-and-light', 'neuron', 'ohms-law', 'optics-lab', 'pendulum-lab', 'ph-scale-basics', 'ph-scale', 'plinko-probability', 'projectile-motion', 'protein-synthesis', 'reactants-products-and-leftovers', 'resistance-in-a-wire', 'scenery-phet', 'seasons', 'shred', 'simula-rasa', 'states-of-matter-basics', 'states-of-matter', 'sugar-and-salt-solutions', 'under-pressure', 'vegas', 'wave-on-a-string' ];
repos.forEach( function( repo ) {
var stringFiles = fs.readdirSync( repo + '/strings' ).filter( function( filename ) {
return (/^.*-strings.*\.json/).test( filename );
} );
var babelDirectory = 'babel/' + repo;
if ( !fs.existsSync( babelDirectory ) ) {
fs.mkdirSync( babelDirectory );
}
stringFiles.forEach( function( filename ) {
var contents = fs.readFileSync( repo + '/strings/' + filename, 'utf8' );
var before = JSON.parse( contents );
var after = {};
for ( var stringKey in before ) {
after[stringKey] = {
value: before[stringKey]
};
}
var newContents = JSON.stringify( after, null, 2 );
var isEnglish = filename.indexOf( '_en.json' ) >= 0;
var oldFilename = repo + '/strings/' + filename;
var resultFilename = ( isEnglish ? repo + '/' : 'babel/' + repo + '/' ) + filename;
console.log( resultFilename );
fs.writeFileSync( resultFilename, newContents, 'utf8' );
child_process.spawn( 'git', [ 'add', resultFilename ] );
child_process.spawn( 'git', [ 'rm', oldFilename ] );
} );
} );
@jonathanolson Sounds like hookes-law was the only repos that you didn't have in your working copy. So closing this issue.
At developer meeting...
build process is now using babel, so we should move translated strings to babel. @jonathanolson volunteered to write a script to do this (which will be faster and less error prone than assigning it to someone to do manually.)