Created
February 3, 2019 03:04
-
-
Save D-side/76127aa002ff6530bf3c65a87d410116 to your computer and use it in GitHub Desktop.
Subnautica translation builder (for the browser console; sample values set for Russian)
This file contains hidden or 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
// You need to be logged in on translate.unknownworlds.com in order to use this script | |
// "https://translate.unknownworlds.com/api/base-strings?project_id=9" | |
// "https://translate.unknownworlds.com/api/strings?project_id=9&language_id=5" | |
let filename = "Russian.json"; | |
let project_id = 9; | |
let language_id = 5; | |
responses = Promise.all([ | |
fetch(`/api/base-strings?project_id=${project_id}`).then(r => r.json()), | |
fetch(`/api/strings?project_id=${project_id}&language_id=${language_id}`).then(r => r.json()) | |
]).then(([base_strings, strings]) => { | |
let translations = {}; | |
for(base of base_strings) { | |
let key = base["key"]; | |
let string = strings.find(s => s["base_string_id"] === base["id"] && s["is_accepted"] == 1); | |
let value = (string == undefined) ? base["text"] : string["text"]; | |
translations[key] = value; | |
} | |
var blob = new Blob([JSON.stringify(translations)], {type: 'application/json'}); | |
// via https://stackoverflow.com/a/20194533 | |
var a = window.document.createElement("a"); | |
a.href = window.URL.createObjectURL(blob); | |
a.download = filename; | |
document.body.appendChild(a); | |
a.click(); | |
document.body.removeChild(a); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment