Last active
August 29, 2015 13:57
-
-
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.
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.