From a8024bbdf527107e52c962b7424c8adf6766f5a0 Mon Sep 17 00:00:00 2001 From: Ole Hejlskov Date: Tue, 8 Aug 2017 17:38:57 +0200 Subject: [PATCH] Add scripts to help the i18n team extract and import stings (#2186) --- scripts/extract-langs.sh | 44 ++++++++++++++++++++++++++++++++++++++++ scripts/import-langs.sh | 26 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100755 scripts/extract-langs.sh create mode 100755 scripts/import-langs.sh diff --git a/scripts/extract-langs.sh b/scripts/extract-langs.sh new file mode 100755 index 0000000000..8e322e5cfa --- /dev/null +++ b/scripts/extract-langs.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash + +if [ $# -eq 0 ]; then + echo "No arguments supplied. Default path for output will be used." + LANGS_OUTPUT="./i18n" +else + LANGS_OUTPUT="$1" +fi + +COMPONENTS_ROOT="ng2-components" + +# Find all directories in $COMPONENTS_ROOT called i18n and add the demo-shell manually +COMPONENTS=(`find $COMPONENTS_ROOT -type d -name i18n`) +COMPONENTS+=("demo-shell-ng2/resources/i18n") + +# Loop the individual components +for COMPONENT_DIR in "${COMPONENTS[@]}" +do : + + echo "Processing $COMPONENT_DIR" + + # Grab *.json in the components i18n dir + FILES=(`find $COMPONENT_DIR -type f -name "*.json"`) + + # Loop each i18n file + for i in "${FILES[@]}" + do : + + # Match the filename and extension into two groups so we can use the name as a folder for the output folder + if [[ $i =~ /([a-zA-Z0-9_-]*)(\.json)$ ]] ; then + + TMP=${BASH_REMATCH[1]} # Will contain "en", "it", "ru" etc. without .json + LANG=`echo "$TMP" | tr '[:lower:]' '[:upper:]'` # Conver to upper case + + # Build the output path, ensure it exists then copy the file + DEST="$LANGS_OUTPUT/$LANG/$COMPONENT_DIR" + echo "\tCopying $i to $DEST" + `mkdir -p $DEST` + `cp $i $DEST` + fi + done + echo "\n" + +done \ No newline at end of file diff --git a/scripts/import-langs.sh b/scripts/import-langs.sh new file mode 100755 index 0000000000..62030a97bf --- /dev/null +++ b/scripts/import-langs.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +if [ $# -eq 0 ]; then + echo "No arguments supplied. You must provide path for the translations" + exit; +else + LANG_ROOT=${1%/} +fi + +# Findn all JSON files +FILES=(`find $LANG_ROOT -type f -name "*.json"`) + +# Loop the individual components +for FILE in "${FILES[@]}" +do : + + echo "Processing $FILE" + # Match the language so we can get to the actual destination + if [[ $FILE =~ /[A-Z0-0_-]+/(.+)$ ]] ; then + + DEST=${BASH_REMATCH[1]} # Will contain the full file path + echo "\tCopying $FILE to $DEST" + `cp $FILE $DEST` + fi + echo "\n" +done \ No newline at end of file