forked from TurboWarp/scratch-blocks
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(still not done) translation scripts
- Loading branch information
1 parent
c5a6b3b
commit 2964bbd
Showing
12 changed files
with
24,060 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Translation Scripts | ||
**NOTE: PenguinMod uses different scripts as we have a different method for translation.** | ||
|
||
These are written for converting the Blockly format to Google Sheets & back. | ||
The Scratch scripts are still used at build time, so we don't remove them. | ||
|
||
Run these files with a file path as the argument if needed. | ||
|
||
Example: `C:/scratch-blocks/i18n> node create_base_xlsx.js ./my_js_file.js` | ||
|
||
## Files | ||
- `messages_fillout.js` | ||
Creates a JS file that merges English text from `msg/messages.js` | ||
into every language in `msg/scratch_msgs.js`. | ||
|
||
**NOTE:** This output shouldn't replace the existing text in `msg/scratch_msgs.js`. | ||
This output is used as input in `create_base_xlsx.js` to create sheets. | ||
|
||
- `create_base_xlsx.js` | ||
Creates an XLSX sheet based on the JS input taken from `msg/scratch_msgs.js` or `messages_fillout.js`. | ||
|
||
- `import_xlsx.js` | ||
Creates a file in the format of `msg/scratch_msgs.js` based on the input XLSX sheet. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fs = require('fs'); | ||
|
||
const linePrefix = 'Blockly.Msg'; | ||
console.log('Parsing files'); | ||
|
||
const EnMessages = fs.readFileSync('../msg/messages.js', 'utf8'); | ||
const EnObject = (() => { | ||
const EnParsable = EnMessages.split('\n') | ||
.filter(line => line.startsWith(linePrefix)) | ||
.join('\n'); | ||
const Blockly = { | ||
Msg: {} | ||
}; | ||
eval(EnParsable); | ||
return Blockly.Msg; | ||
})(); | ||
|
||
// write en.json because its just json.stringify | ||
console.log('writing json file'); | ||
fs.writeFileSync('../msg/output/en.json', JSON.stringify(EnObject, null, 4), 'utf8'); | ||
|
||
// write en.js | ||
console.log('writing en.js'); | ||
let fileText = `// This file was automatically generated. Do not modify. | ||
'use strict'; | ||
goog.provide('Blockly.Msg.en'); | ||
goog.require('Blockly.Msg'); | ||
`; | ||
for (const key in EnObject) { | ||
const value = EnObject[key]; | ||
fileText += `Blockly.Msg[${JSON.stringify(key)}] = ${JSON.stringify(value)};\n` | ||
} | ||
fs.writeFileSync('../msg/output/en.js', fileText, 'utf8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const fs = require('fs'); | ||
|
||
const linePrefix = 'Blockly.Msg'; | ||
console.log('Parsing files'); | ||
|
||
const EnMessages = fs.readFileSync('../msg/messages.js', 'utf8'); | ||
const CombinedMessages = fs.readFileSync('../msg/scratch_msgs.js', 'utf8'); | ||
|
||
const CombinedObject = (() => { | ||
const goog = { | ||
provide: () => {}, | ||
require: () => {}, | ||
}; | ||
const Blockly = { | ||
ScratchMsgs: { | ||
locales: {} | ||
} | ||
}; | ||
eval(CombinedMessages.replace("'use strict';", '')); | ||
return Blockly.ScratchMsgs.locales; | ||
})(); | ||
const EnObject = (() => { | ||
const EnParsable = EnMessages.split('\n') | ||
.filter(line => line.startsWith(linePrefix)) | ||
.join('\n'); | ||
const Blockly = { | ||
Msg: {} | ||
}; | ||
eval(EnParsable); | ||
return Blockly.Msg; | ||
})(); | ||
|
||
console.log('filling'); | ||
|
||
// merge english if the keys dont exist in the lang | ||
for (const langCode in CombinedObject) { | ||
const language = CombinedObject[langCode]; | ||
for (const key in EnObject) { | ||
if (!(key in language)) { | ||
language[key] = EnObject[key]; | ||
console.log('filled', langCode, 'missing', key); | ||
} | ||
} | ||
} | ||
|
||
console.log('Saving to file...'); | ||
let fileText = `// This file was automatically generated. Do not modify. | ||
'use strict'; | ||
goog.provide('Blockly.ScratchMsgs.allLocales'); | ||
goog.require('Blockly.ScratchMsgs'); | ||
`; | ||
for (const langCode in CombinedObject) { | ||
const language = CombinedObject[langCode]; | ||
fileText += `\nBlockly.ScratchMsgs.locales[${JSON.stringify(langCode)}] =\n` | ||
fileText += `${JSON.stringify(language, null, 4)};\n`; | ||
} | ||
fileText += `// End of combined translations\n`; | ||
fs.writeFileSync('../msg/output/filled_scratch_msgs.js', fileText, 'utf8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# / (root) | ||
Important files for PenguinMod block text | ||
|
||
- `messages.js`: Editable file, used for creating translations. Add default english text here. | ||
- `scratch_msgs.js`: Script-generated file, used by scratch-blocks. Contains all languages. | ||
|
||
# /js | ||
Default language block files (JS) | ||
|
||
- `en.js`: Script-generated file, used by scratch-blocks. Contains default english text in JS. | ||
|
||
# /json | ||
Default language block files (JSON) | ||
|
||
- `en.json`: Script-generated file, used by scratch-blocks. Contains default english text in JSON. | ||
|
||
# /output | ||
Script-generated files by the custom PenguinMod Scripts (NOT the Scratch scripts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,13 +20,26 @@ | |
|
||
/** | ||
* @fileoverview English strings. | ||
* @author [email protected] (Andrew Sliwinski) | ||
* @author [email protected] (Andrew Sliwinski) PenguinMod for PM Scripts | ||
* | ||
* After modifying this file, run `npm run translate` from the root directory | ||
* to regenerate `./msg/json/en.json`. | ||
* IMPORTANT: | ||
* All message strings must use single quotes for the scripts to work properly | ||
*/ | ||
* PENGUINMOD SCRIPT INSTRUCTIONS | ||
* All message strings must use single quotes for the build scripts to work properly. | ||
* Lines starting with "Blockly.Msg" will be evaluated as JS. This likely doesn't apply in the build scripts. | ||
* Make sure to import the translations from the google sheet before running any scripts! | ||
* After modifying this file: | ||
* 1. Run the i18n/create_en_msgs script and replace msg/js/en.js and msg/json/en.json with the output | ||
* 2. Run the i18n/messages_fillout script for sheet creation (make sure you imported the translations from the google sheet first) | ||
* 2.5. If you modified the text of a translation key, run i18n/messages_override with the generated filled_scratch_msgs.js from step 2 as an argument to the script & then specify the changed keys as arguments after. | ||
* 3. Generate an XLSX file with i18n/create_base_xlsx for translation | ||
* 4. Please update the Google Sheets if you have access (otherwise, someone with access needs to update it later) | ||
*/ | ||
|
||
// SCRATCH SCRIPT INSTRUCTIONS (NOT REQUIRED IN PM) | ||
// After modifying this file, run `npm run translate` from the root directory | ||
// to regenerate `./msg/json/en.json`. | ||
// IMPORTANT: | ||
// All message strings must use single quotes for the scripts to work properly | ||
|
||
'use strict'; | ||
|
||
goog.provide('Blockly.Msg.en'); | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.