Skip to content

Instantly share code, notes, and snippets.

@vanclist
Last active April 5, 2018 07:38
Show Gist options
  • Save vanclist/2a2cd38ae68a28ed63cc160c369cc8b7 to your computer and use it in GitHub Desktop.
Save vanclist/2a2cd38ae68a28ed63cc160c369cc8b7 to your computer and use it in GitHub Desktop.
List all i18n-ed strings in *.js files
from pprint import pprint
import subprocess
from bs4 import BeautifulSoup
def parse(document):
soup = BeautifulSoup(document, 'lxml')
return [text for text in soup.stripped_strings if text.startswith("<%= i18n")]
def read(path):
with open(path, "r") as doc:
return parse(doc)
def list_js_files(directory):
return subprocess.check_output(
["find",
directory,
"-name",
"*.js"]).split()
[pprint((f, read(f))) for f in list_js_files("~/ui/src/")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment