Skip to content

Instantly share code, notes, and snippets.

@jonasbits
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasbits/9560552 to your computer and use it in GitHub Desktop.
Save jonasbits/9560552 to your computer and use it in GitHub Desktop.
mkgoogle.sh - convert blockchain.info json language files # # to this specification http://developer.chrome.com/extensions/i18n # to be used with this tool http://translate.google.com/toolkit # The optional "description" tag provides context to translators # but is not yet included by this script.
#!/bin/bash
########################
#
# mkgoogle.sh - convert blockchain.info json language files
#
# to this specification http://developer.chrome.com/extensions/i18n
# to be used with this tool http://translate.google.com/toolkit
# The optional "description" tag provides context to translators
# but is not yet included by this script.
#
########################
GJSON=('s/\"\s\:\s\"/" : {"message": "/')
# ^to this
GMISSING=('s/\"$/\"\,/')
# ^add this to lines missing it
GSTRANGE=('s/\"\s\,/",/')
# ^strange space found once
GEND=('s/\"\,/"},/')
# ^add this bracket
GSELECT=('.*\"\s\:\s\{\"message')
#
# Step 1. PARSE AND SPLIT
sed -e "$GJSON" -e "$GMISSING" -e "$GSTRANGE" -e "$GEND" language.json | grep -P "$GSELECT" | split -l '99' - 'eng-'
# Step 2. Add start and ending, make json tidy.
START='{'
# This needs a better solution:
# Detect EOF and remove the comma instead of inserting this dummy.
ENDLINE=('"" : {"message": ""} }')
# Is there a solution where this file is not needed?
echo "$ENDLINE" > endline.json
for F in eng-??; do
echo "$START" | cat - "$F" endline.json | python -mjson.tool > "$F".json && rm "$F" || echo "$F" "faild the last step"
done
rm endline.json
@jonasbits
Copy link
Author

this script have a fatal flaw, it removes duplicates in the json. This is because Blockchain.info uses nested JSON and Google Chrome JSON is flat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment