Skip to content

Instantly share code, notes, and snippets.

@theosp
Last active August 29, 2015 14:07
Show Gist options
  • Save theosp/559117bed5fd6996694c to your computer and use it in GitHub Desktop.
Save theosp/559117bed5fd6996694c to your computer and use it in GitHub Desktop.
The migration script to make Telescope tap:i18n ready
#!/bin/bash
keys=("1 notification" "Account" "Add Comment" "Admin" "Administration" "All" "Already have an account?" "A new comment on your post" "Approved" "Are you sure?" "Are you sure you want to delete " "baseScore" "Best" "Bio" "Body" "Categories" "Category" "Change Password?" "clicks" "comment" "Comment" "comments" "Comments" "Comments on my posts" "Created" "Date" "Delete" "Delete Comment" "Delete Post" "Delete User" "Digest" "Discuss" "Display Name" "Don\'t have an account?" "downvote" "Edit" "Edit Account" "Edit profile" "Email" "Email Notifications" "Filter by" "Forgot password?" " has created a new post" " has replied to your comment on" "inactive" "Inactive?" "Invite " "Invite" "Invited" "Invite (none left)" "Is Admin?" "Is Invited?" "Karma" "left" "link" "Loading..." "Load more" "Make admin" "Mark all as read" "Member since" "Menu" "My Account" "Name" "New" "New Password" "New Posts" "Next Day" "No comments." "No notifications" "Note: this post is still pending so it has no submission timestamp yet." "Not Found!" "notifications" "Old Password" " on your post" "Password" "Password reset link sent!" "Pending" "Please complete your profile below before continuing." "Please fill in a headline" "Please fill in all fields" "Please fill in an URL first!" "Please fill in your email below to finish signing up." "Please log in first" "Please Sign In First." "Please wait " "point" "points" "Post" "Posts" " posts per day" "Previous Day" "Profile updated" "Read more" "Rejected" "Replies to my comments" "Reply" "Reset Password" "score" " seconds before commenting again" "Settings" "Share" "Short URL" "Sign in!" "Sign In" "Sign In\/Sign Up with Twitter" "Sign up!" "Sign Up" "Sign Up\/Sign In" "Someone replied to your comment on" "Sorry, couldn\'t find a title..." "Sorry, no posts for" "Sorry, no posts for today" "Sorry, this is a private site. Please sign up first." "Sorry, you cannot edit this comment." "Sorry, you cannot edit this post." "Sorry, you cannot submit more than " "Sorry, you do not have access to this page" "Sorry, you don\'t have permissions to add new items." "Sorry, you don\'t have the rights to view this page." "Sorry, you have to be an admin to view this page." "Sort by" "Start posting." "status" "Status" "Sticky?" "Sticky" "Submission" "Submission Date" "Submission Time" "Submit" "Suggest title" "Thanks for signing up!" "Thanks, your post is awaiting approval." "The site is currently invite-only, but we will let you know as soon as a spot opens up." "The top 5 posts of each day." "This link has already been posted" "Title" "Today" "Toolbox" "Top" "Unadmin" "Uninvite" "Uninvited" "upvote" "Upvote" "URL" "User" "Username" "Users" "View" "View Profile" "views" "votes" "Welcome to " "We\'re sorry; whatever you were looking for isn\'t here.." "Yesterday" "You are already logged in" "You don\'t have permission to delete this comment." "You have a new comment by " "You must be logged in." "You need to login and be an admin to add a new category." "You need to login or be invited to post new comments." "You need to login or be invited to post new stories." "Your account has been approved." "Your comment has been deleted." "Your comment is empty." "Your post has been deleted." "Please fill in a title" " seconds before posting again" "Upvoted" "Posted Date" "Posted Time" "Posted Date" "Posted Time" "Profile" "Sign Out" "InvitedCount" "Invites" "Invited?" "Admin?" "Actions" "invites left" "ID" "Name:" "Bio:" "GitHub" "Site" "Upvoted Posts" "Downvoted Posts" "Mark as read")
special_keys=("Comment" "Comments" "Inactive?" "Invite " "Sign in!" "Sign up!" "Status" "Sticky?" "Upvote")
special_values=("comment_" "comments_" "inactive_" "invite_" "sign_in_" "sign_up_" "status_" "sticky_" "upvote_")
cd Telescope
i=0
for key in "${keys[@]}"; do
sterilized=0
j=0
for special_key in "${special_keys[@]}"; do
special_value="${special_values[$j]}"
if [[ "$key" == "$special_key" ]]; then key="$special_key"; value="$special_value"; sterilized=1; fi
j=$(($j + 1))
done
if (( $sterilized == 0 )); then
value=$(node -e "console.log('$key'.toLowerCase().replace(/[']+/g, '').replace(/[()-\/\s,!\.;?:]+/g, '_').replace(/_+/g, '_').replace(/^_+/g, '').replace(/_+$/g, ''))") #"${values[$i]}"
key=$(node -e "console.log('$key'.replace('/', '\\\\/').replace('\\\\\'', '\''))")
else
echo "Special Key"
fi
echo "$i. s/$key/$value/g"
regex=$'s/\(i18n\s\+["\']\|i18n.t(["\']\)'$key$'\(["\']\)/\\1'$value$'\\2/g'
find \( ! -regex '.*/\..*' \) -type f -exec sed -i -e "$regex" {} \;
regex=$'s/\(["\']\)'$key$'\(["\']\):/\\1'$value$'\\2:/g'
find . -regex '.*\.i18n.json' -type f -exec sed -i -e "$regex" {} \;
i=$(($i + 1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment