Skip to content

Instantly share code, notes, and snippets.

@drewbrokke
Last active February 23, 2017 00:27
Show Gist options
  • Save drewbrokke/683b174ab3eeaf11b3d780792aa64651 to your computer and use it in GitHub Desktop.
Save drewbrokke/683b174ab3eeaf11b3d780792aa64651 to your computer and use it in GitHub Desktop.
Langify - turn sentences into language properties

langify

transform a file full of sentences into the Language.properties format

Usage

langify ./path/to/sentences/file.txt

It will take a file with these contents (that blank line at the end needs to be there):

This is the first sentence.  It's pretty great.
Isn't the second sentence better?  I think so.
The third sentence must be the best!  Yes, the best!

and spit out some langified output:

this-is-the-first-sentence=This is the first sentence.  It's pretty great.
isn't-the-second-sentence-better=Isn't the second sentence better?  I think so.
the-third-sentence-must-be-the-best=The third sentence must be the best!  Yes, the best!
#!/bin/bash
function langify() {
local INPUT="${1:?There must be a value to langify}"
local FIRST_SENTENCE="${INPUT%%[.\?!]*}"
local KEY="$(tr '[:upper:] ' '[:lower:]-' <<< "${FIRST_SENTENCE}")"
echo "${KEY}=${INPUT}"
}
FILENAME="${1:?Please supply a file path to read}"
while read -r LINE ; do
langify "${LINE}"
done < "${FILENAME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment