]> git.p6c8.net - jirafeau_project.git/commitdiff
[TASK] Add scripts to add, remove and delete locales
authorJerome Jutteau <j.jutteau@gmail.com>
Fri, 9 Feb 2018 12:11:42 +0000 (13:11 +0100)
committerJerome Jutteau <j.jutteau@gmail.com>
Fri, 16 Feb 2018 17:18:59 +0000 (18:18 +0100)
Signed-off-by: Jerome Jutteau <j.jutteau@gmail.com>
lib/locales/add.sh [new file with mode: 0755]
lib/locales/remove.sh [new file with mode: 0755]
lib/locales/rename.sh [new file with mode: 0755]

diff --git a/lib/locales/add.sh b/lib/locales/add.sh
new file mode 100755 (executable)
index 0000000..aba8bc9
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -e
+new=$1
+if [ -z "$new" ]; then
+    echo "please pass the new string id to add as parameter"
+    exit 1
+fi
+locales_dir=$(cd "$(dirname $0)" && pwd)
+new_line="    \"$new\": \"\","
+find $locales_dir -type f -name "*.json" -print0 | xargs -0 sed -i "s/{/{\n${new_line}/"
diff --git a/lib/locales/remove.sh b/lib/locales/remove.sh
new file mode 100755 (executable)
index 0000000..865752d
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+set -e
+id=$1
+if [ -z "$id" ]; then
+    echo "please pass the string id to remove as parameter"
+    exit 1
+fi
+locales_dir=$(cd "$(dirname $0)" && pwd)
+find $locales_dir -type f -name "*.json" -print0 | xargs -0 sed -i "/$id/d"
diff --git a/lib/locales/rename.sh b/lib/locales/rename.sh
new file mode 100755 (executable)
index 0000000..7477d5e
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/bash
+original_id=$1
+new_id=$2
+if [ -z "$original_id" ] || [ -z "$new_id" ] ; then
+    echo "arguments: [OLD_ID] [NEW_ID]"
+    exit 1
+fi
+locales_dir=$(cd "$(dirname $0)" && pwd)
+o="\"$original_id\":"
+i="\"$new_id\":"
+find . -type f -name "*.json" -print0 | xargs -0 sed -i "s/$o/$i/g"
+

patrick-canterino.de